资源描述:
《lists算法竞赛入门经典刘汝佳》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、127-"Accordian"PatienceYouaretosimulatetheplayingofgamesof''Accordian"patience,therulesforwhichareasfollows:Dealcardsonebyoneinarowfromlefttoright,notoverlapping.Wheneverthecardmatchesitsimmediateneighbourontheleft,ormatchesthethirdcardtotheleft,itmaybemovedontothatcard.
2、Cardsmatchiftheyareofthesamesuitorsamerank.Aftermakingamove,looktoseeifithasmadeadditionalmovespossible.Onlythetopcardofeachpilemaybemovedatanygiventime.Gapsbetweenpilesshouldbeclosedupassoonastheyappearbymovingallpilesontherightofthegaponepositiontotheleft.Dealoutthewho
3、lepack,combiningcardstowardstheleftwheneverpossible.Thegameiswonifthepackisreducedtoasinglepile.Situationscanarisewheremorethanoneplayispossible.Wheretwocardsmaybemoved,youshouldadoptthestrategyofalwaysmovingtheleftmostcardpossible.Whereacardmaybemovedeitheronepositionto
4、theleftorthreepositionstotheleft,moveitthreepositions.InputInputdatatotheprogramspecifiestheorderinwhichcardsaredealtfromthepack.Theinputcontainspairsoflines,eachlinecontaining26cardsseparatedbysinglespacecharacters.Thefinallineoftheinputfilecontainsa#asitsfirstcharacter
5、.Cardsarerepresentedasatwocharactercode.Thefirstcharacteristheface-value(A=Ace,2-9,T=10,J=Jack,Q=Queen,K=King)andthesecondcharacteristhesuit(C=Clubs?D=Diamonds,H=Hearts,S=Spades).OutputOnelineofoutputmustbeproducedforeachpairoflines(thatbetweenthemdescribeapackof52cards)
6、intheinput.Eachlineofoutputshowsthenumberofcardsineachofthepilesremainingafterplaying''Accordianpatience"withthepackofcardsasdescribedbythecorrespondingpairsofinputlines.SampleInputQDAD8H5S3H5HTC4DJHKS6H8SJSACAS8D2HQSTS3SAH4HTHTD3C6S8C7D4C4S7S9H7C5D2SKD2DQHJD6D9DJC2CKH3D
7、QC6C9SKC7H9C5CAC2C3C4C5C6C7C8C9CTCJCQCKCAD2D3D4D5D6D7D8DTD9DJDQDKDAH2H3H4H5H6H7H8H9HKH6SQHTHAS2S3S4S5SJH7S8S9STSJSQSKS#SampleOutput6pilesremaining:40811111pileremaining:52101■TheBlocksProblemBackgroundManyareasofComputerScienceusesimple,abstractdomainsforbothanalyticalan
8、dempiricalstudies.Forexample,anearlyAlstudyofplanningandrobotics(STRIPS)usedablockworldinwhicharobotarm