资源描述:
《2001年第13届国际信息学奥赛试题》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、2001年第13届国际信息学奥赛试题解析芬兰第一题Ioiwari游戏IoiwariGameDay1.Sourcefileioiwari.*Availablememory:32MB.Maximumrunningtime:1s.Problem:TheMancalafamilyofgameswithbeadsandpitsisamongtheoldestformsofhumanentertainment.ThistaskintrouducesaversionofthegameespeciallydevelopedfortheIOI.Thegame
2、isplayedbytwoplayersonaroundboardwithsevenpitsaroundtheedge.Inaddition,thereisabankforeachplayer.Thegamebeginsbyrandomlydistributing20beadsintothepitssothateachpitcontainsatleast2andatmost4beads.Thetwoplayersmovealternately.Tomove,theplayerchoosesanon-emptypitandtakesallbe
3、adsoutofthepit,andholdstheminherhand.Aslongastherearebeadsintheplayer’shand,sheconsidersthepitsinclockwiseorder,startingoneaftertheemptiedone,andperformsthefollowingoperations:·Morethanonebeadinyourhand:Ifthecurrentpitalreadycontains5beads,thentakeonebeadoutofthecurrentpit
4、andplaceitintoyourbank,otherwiseplaceonebeadfromyourhandintothecurrentpit.·Onebeadinyourhand:Ifthecurrentpitcontainsatleastoneandatmostfourbeadsthenmoveallbeadsfromthepitandtheonefromyourhandintoyourbank,otherwise(thepitcontains0or5beads)placethebeadinyourhandintotheoppone
5、nt’sbank.Thegameisoverwhenallpitsareemptyandthewinneristheplayerwithmost-beadsinherbank.Thestartingplayeralwayshasawinningstrategy.Youaretowriteaprogram,whichplaysIloiwariasthestartingplayerandwins.Theevaluationopponentplaysoptimally,thatis,oncegivenachance,itwillwinandyou
6、rprogramwilllose.Inputandoutput:Yourprogramreadsinputfromstandardinputandwritesoutputtostandardoutput.Yourprogramisplayer1,andtheopponentisplayer2.Whenyourprogramisstarted,itmustfirstreadalinewith7integersp1,..p7,theinitialnumberofbeadsinpits1,..7,respectively.Thepitsarela
7、beledwithintegersfrom1to7inclockwisedirectionontheboard.Afterthis,thegamestartswithemptybanks,Yourprogramshouldplayasfollows:·Ifitisyourprogram’sturntomove,thenyourprogramshouldwritethelabelofthepitdescribingthemovetostandardoutput·Ifitisyourprogram’sopponent’sturntomove,t
8、henyourprogramshouldreadthelabelofthepitdefiningthemove(thepitfromwhichthebeadsareremoved