您的位置:首页 > 其它

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.

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: