ZOJ Problem Set - 1003Crashing Balloon
2011-07-25 22:03
246 查看
CrashingBalloonTimeLimit:1SecondMemoryLimit:32768KB
OneveryJune1st,theChildren'sDay,therewillbeagamenamed"crashingballoon"onTV.Theruleisverysimple.Onthegroundthereare100labeledballoons,withthenumbers1to100.Aftertherefereeshouts"Let'sgo!"thetwoplayers,whoeachstartswithascoreof"1",racetocrashtheballoonsbytheirfeetand,atthesametime,multiplytheirscoresbythenumberswrittenontheballoonstheycrash.Afteraminute,thelittleaudiencesareallowedtotaketheremainingballoonsaway,andeachcontestantreportshis\herscore,theproductofthenumbersontheballoonshe\she'scrashed.Theunofficialwinneristheplayerwhoannouncedthehighestscore.
Inevitably,though,disputesarise,andsotheofficialwinnerisnotdetermineduntilthedisputesareresolved.Theplayerwhoclaimsthelowerscoreisentitledtochallengehis\heropponent'sscore.Theplayerwiththelowerscoreispresumedtohavetoldthetruth,becauseifhe\sheweretolieabouthis\herscore,he\shewouldsurelycomeupwithabiggerbetterlie.Thechallengeisupheldiftheplayerwiththehigherscorehasascorethatcannotbeachievedwithballoonsnotcrashedbythechallengingplayer.So,ifthechallengeissuccessful,theplayerclaimingthelowerscorewins.
So,forexample,ifoneplayerclaims343pointsandtheotherclaims49,thenclearlythefirstplayerislying;theonlywaytoscore343isbycrashingballoonslabeled7and49,andtheonlywaytoscore49isbycrashingaballoonlabeled49.Sinceeachoftwoscoresrequirescrashingtheballoonlabeled49,theoneclaiming343pointsispresumedtobelying.
Ontheotherhand,ifoneplayerclaims162pointsandtheotherclaims81,itispossibleforbothtobetellingthetruth(e.g.onecrashesballoons2,3and27,whiletheothercrashesballoon81),sothechallengewouldnotbeupheld.
Bytheway,ifthechallengermadeamistakeoncalculatinghis/herscore,thenthechallengewouldnotbeupheld.Forexample,ifoneplayerclaims10001pointsandtheotherclaims10003,thenclearlynoneofthemaretellingthetruth.Inthiscase,thechallengewouldnotbeupheld.
Unfortunately,anyonewhoiswillingtorefereeagameofcrashingballoonislikelytogetover-excitedinthehotatmospherethathe\shecouldnotreasonablybeexpectedtoperformtheintricatecalculationsthatrefereeingrequires.Hencetheneedforyou,soberprogrammer,toprovideasoftwaresolution.
OneveryJune1st,theChildren'sDay,therewillbeagamenamed"crashingballoon"onTV.Theruleisverysimple.Onthegroundthereare100labeledballoons,withthenumbers1to100.Aftertherefereeshouts"Let'sgo!"thetwoplayers,whoeachstartswithascoreof"1",racetocrashtheballoonsbytheirfeetand,atthesametime,multiplytheirscoresbythenumberswrittenontheballoonstheycrash.Afteraminute,thelittleaudiencesareallowedtotaketheremainingballoonsaway,andeachcontestantreportshis\herscore,theproductofthenumbersontheballoonshe\she'scrashed.Theunofficialwinneristheplayerwhoannouncedthehighestscore.
Inevitably,though,disputesarise,andsotheofficialwinnerisnotdetermineduntilthedisputesareresolved.Theplayerwhoclaimsthelowerscoreisentitledtochallengehis\heropponent'sscore.Theplayerwiththelowerscoreispresumedtohavetoldthetruth,becauseifhe\sheweretolieabouthis\herscore,he\shewouldsurelycomeupwithabiggerbetterlie.Thechallengeisupheldiftheplayerwiththehigherscorehasascorethatcannotbeachievedwithballoonsnotcrashedbythechallengingplayer.So,ifthechallengeissuccessful,theplayerclaimingthelowerscorewins.
So,forexample,ifoneplayerclaims343pointsandtheotherclaims49,thenclearlythefirstplayerislying;theonlywaytoscore343isbycrashingballoonslabeled7and49,andtheonlywaytoscore49isbycrashingaballoonlabeled49.Sinceeachoftwoscoresrequirescrashingtheballoonlabeled49,theoneclaiming343pointsispresumedtobelying.
Ontheotherhand,ifoneplayerclaims162pointsandtheotherclaims81,itispossibleforbothtobetellingthetruth(e.g.onecrashesballoons2,3and27,whiletheothercrashesballoon81),sothechallengewouldnotbeupheld.
Bytheway,ifthechallengermadeamistakeoncalculatinghis/herscore,thenthechallengewouldnotbeupheld.Forexample,ifoneplayerclaims10001pointsandtheotherclaims10003,thenclearlynoneofthemaretellingthetruth.Inthiscase,thechallengewouldnotbeupheld.
Unfortunately,anyonewhoiswillingtorefereeagameofcrashingballoonislikelytogetover-excitedinthehotatmospherethathe\shecouldnotreasonablybeexpectedtoperformtheintricatecalculationsthatrefereeingrequires.Hencetheneedforyou,soberprogrammer,toprovideasoftwaresolution.
Input
Pairsofunequal,positivenumbers,witheachpaironasingleline,thatareclaimedscoresfromagameofcrashingballoon.Output
Numbers,onetoaline,thatarethewinningscores,assumingthattheplayerwiththelowerscorealwayschallengestheoutcome.SampleInput
34349 3599610 6236
SampleOutput
49 610 62
//zju1003
#include<stdio.h>
boolaTrue,bTrue;
intjudge(intm,intn,intp)
{
if(aTrue)return0;
if(m==1&&n==1)//两个队员的分数都是正确的
{
aTrue=true;return0;//aTrue是赢家
}
if(n==1)bTrue=true;//如果n正确,bTrue就是赢家
while(p>1)
{
if(m%p==0)judge(m/p,n,p-1);
if(n%p==0)judge(m,n/p,p-1);
p--;
}
return0;
}
intmain()
{
inta,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
if(a<b)//如果a<b,交换
{inttemp=a;a=b;b=temp;}
aTrue=false;bTrue=false;//aTrue和bTrue的初值
judge(a,b,100);
if(!aTrue&&bTrue)//aTrue不成立,bTrue成立
printf("%d\n",b);//输出b
else
printf("%d\n",a);//否则输出a
}
return0;
}
相关文章推荐
- ZOJ Problem Set - 1048 Financial Management
- ZOJ Problem Set–1858 Soundex
- ZOJ Problem Set–1828 Fibonacci Numbers
- ZOJ Problem Set - 1001
- ZOJ Problem Set–2201 No Brainer
- ZOJ Problem Set–1860 Dog & Gopher
- ZOJ Problem Set - 2970 Faster, Higher, Stronger
- ZOJ Problem Set - 2297 Survival 【状压dp】
- ZOJ Problem Set - 1003 Crashing Balloon
- ZOJ Problem Set - 1001 A + B Problem
- ZOJ Problem Set - 3958―Cooking Competition
- ZOJ Problem Set - 1078 Palindrom Numbers
- ZOJ Problem Set - 1216 Deck
- ZOJ Problem Set - G Goldbach
- ZOJ Problem Set - 3632 Watermelon Full of Water
- ZOJ Problem Set - 1526
- ZOJ Problem Set - 1091
- ZOJ Problem Set - 2947 Abbreviation
- ZOJ Problem Set - 1078(十进制对任意进制转换)
- ZOJ Problem Set – 1056 The Worm Turns