山东省赛ACM真题重点.docx
《山东省赛ACM真题重点.docx》由会员分享,可在线阅读,更多相关《山东省赛ACM真题重点.docx(15页珍藏版)》请在冰豆网上搜索。
山东省赛ACM真题重点
ProblemAPhoneNumber
WeknowthatifaphonenumberAisanotherphonenumberB’sprefix,Bisnotabletobecalled.Foranexample,Ais123whileBis12345,afterpressing123,wecallA,andnotabletocallB.
GivenNphonenumbers,yourtaskistofindwhetherthereexitstwonumbersAandBthatAisB’sprefix.
Input
Theinputconsistsofseveraltestcases.
ThefirstlineofinputineachtestcasecontainsoneintegerN(0ThenextlinecontainsNintegers,describingthephonenumbers.
Thelastcaseisfollowedbyalinecontainingonezero.
Output
Foreachtestcase,ifthereexitsaphonenumberthatcannotbecalled,print“NO”,otherwiseprint“YES”instead.
SampleInputOutputfortheSampleInput
2
012
012345
2
12
012345
0
NO
YES
ProblemBBalloons
BothSayaandKudolikeballoons.Oneday,theyheardthatinthecentralpark,therewillbethousandsofpeopleflyballoonstopatternabigimage.
Theywereveryinterestedaboutthisevent,andalsocuriousabouttheimage.
Sincetherearetoomanyballoons,itisveryhardforthemtocomputeanythingtheyneed.Canyouhelpthem?
YoucanassumethattheimageisanN*Nmatrix,whileeachelementcanbeeitherballoonsorblank.
SupposeelementAandelementBarebothballoons.Theyareconnectedif:
iTheyareadjacent;
iiThereisalistofelementC1,C2,…,Cn,whileAandC1areconnected,C1andC2areconnected…CnandBareconnected.
Andaconnectedblockmeansthateverypairofelementsintheblockisconnected,whileanyelementintheblockisnotconnectedwithanyelementoutoftheblock.
ToSaya,elementA
andB
isadjacentif
ButtoKudo,elementA
andelementB
isadjacentif
and
Theywanttoknowthatthere’showmanyconnectedblockswiththereowndefinitionofadjacent?
Input
Theinputconsistsofseveraltestcases.
ThefirstlineofinputineachtestcasecontainsoneintegerN(0EachofthenextNlinescontainsastringwhoselengthisN,representstheelementsofthematrix.Thestringonlyconsistsof0and1,while0representsablockand1representsballoons.
Thelastcaseisfollowedbyalinecontainingonezero.
Output
Foreachcase,printthecasenumber(1,2…andtheconnectedblock’snumberswithSayaandKudo’sdefinition.Youroutputformatshouldimitatethesampleoutput.Printablanklineaftereachtestcase.
SampleInputOutputfortheSampleInput
5
11001
00100
11111
11010
10010
0
Case1:
32
ProblemCClockwise
SayahavealongnecklacewithNbeads,andshesignsthebeadsfrom1toN.ThenshefixesthemtothewalltoshowN-1vectors–vectoristartsfrombeadiandendupwithbeadi+1.
Oneday,KudocomestoSaya’shome,andsheseesthebeadsonthewall.Kudosaysitisnotbeautiful,andletSayamakeitbetter.
Shesays:
“Ithinkitwillbebetterifitisclockwiserotation.Itmeansthattoanyvectori(i-1,itwillhavethesamedirectionwithvectori+1afterclockwiserotateTdegrees,while0≤T<180.”
ItishardforSayatoresetthebeads’places,soshecanonlyremovesomebeads.Tosavingthebeads,althoughsheagreeswithKudo’ssuggestion,shethinkscounterclockwiserotationisalsoacceptable.Acounterclockwiserotationmeanstoanyvectori(i-1,itwillhavethesamedirectionwithvectori+1aftercounterclockwiserotateTdegrees,while0≤180.”
Sayastartstocomputeatleasthowmanybeadssheshouldremovetomakeaclockwiserotationoracounterclockwiserotation.
Sincethenecklaceisvery-verylong,canyouhelphertosolvethisproblem?
Input
Theinputconsistsofseveraltestcases.
ThefirstlineofinputineachtestcasecontainsoneintegerN(2EachofthenextNlinescontainstwointegerxandy,representsthecoordinateofthebeads.Youcanassumethat0Thelastcaseisfollowedbyalinecontainingonezero.
Output
Foreachcase,printyouranswerwiththefollowingformat:
Ifitisclockwiserotationwithoutremovinganybeads,pleaseprint“C;otherwiseifitiscounterclockwiserotationwithoutremovinganybeads,print“CC”instead;otherwise,supposeremoveatleastxbeadstomakeaclockwiserotationandremoveatleastybeadstomakeacounterclockwiserotation.Ifx≤y,print“Removexbead(s,C”,otherwiseprint“Removexbead(s,CC”instead.
Youroutputformatshouldimitatethesampleoutput.Printablanklineaftereachtestcase.
SampleInputOutputfortheSampleInput
3
11
22
33
3
p11
22
pspan11p
4
11
22
33
22
0
C
CC
Remove1bead(s,C
ProblemDShopping
SayaandKudogoshoppingtogether.
Youcanassumethestreetasastraightline,whiletheshopsaresomepointsontheline.
Theyparktheircarattheleftmostshop,visitalltheshopsfromlefttoright,andgobacktotheircar.
Yourtaskistocalculatethelengthoftheirroute.
Input
Theinputconsistsofseveraltestcases.
ThefirstlineofinputineachtestcasecontainsoneintegerN(0ThenextlinecontainsNintegers,describingthesituationoftheshops.Youcanassumethatthesituationsoftheshopsarenon-negativeintegerandsmallerthan2^30.
Thelastcaseisfollowedbyalinecontainingonezero.
Output
Foreachtestcase,printthelengthoftheirshoppingroute.
SampleInputOutputfortheSampleInput
4
24138937
6
73041143942
0
152
70
Explanationforthefirstsample:
Theyparktheircaratshop13;gotoshop24,37and89andfinallyreturntoshop13.Thetotallengthis(24-13+(37-24+(89-37+(89-13=152
ProblemEEmergency
Kudo’srealnameisnotKudo.HernameisKudryavkaAnatolyevnaStrugatskia,andKudoisonlyhernickname.
Now,sheisfacinganemergencyinherhometown:
Hermotherisdevelopinganewkindofspacecraft.Thisplancostsenormousenergybutfinallyfailed.What’smore,becauseofthefailedproject,thegovernmentdoesn’thaveenoughresourcetakemeasuretotherisingsealevelscausedbyglobalwarming,leadtoanislandfloodedbythesea.
Dissatisfiedwithhermother’sspacecraftandthegovernment,civilwarhasbrokenout.Thefoewantstoarrestthespacecraftproject’sparticipantsandthe“Chiefcriminal”–Kudo’smother–DoctorT’sfamily.
Atthebeginningofthewar,allthecitiesareoccupiedbythefoe.Butastimegoesby,thecitiesrecapturedonebyone.
Topreventfromthefoe’sarrestandboostmorale,Kudoandsomeotherpeoplehavetodistractfromacitytoanother.Althoughtheycanusesomeothermeanstotransport,themostconvenientwayisusingtheinter-cityroads.Assumingthecityasanodeandaninter-cityroadasanedge,youcantreatthemapasaweighteddirectedmultigraph.Aninter-cityroadisavailableifbothitsendpointisrecaptured.
Herecomestheproblem.
Giventhetrafficmap,andtherecapturedsituation,canyoutellKudowhat’stheshortestpathfromonecitytoanotheronlypassingtherecapturedcities?
Input
Theinputconsistsofseveraltestcases.
ThefirstlineofinputineachtestcasecontainsthreeintegersN(0EachofthenextMlinescontainsthreeintegerx,yandz,representsthereisaninter-cityroadstartsfromx,endupwithyandthelengthisz.Youcanassumethat0EachofthenextQlinescontainstheoperationswiththefollowingformat:
a0x–meanscityxhasjustbeenrecaptured.
b1xy–meansaskingtheshortestpathfromxtoyonlypassingtherecapturedcities.
Thelastcaseisfollowedbyalinecontainingthreezeros.
Output
Foreachcase,printthecasenumber(1,2…first.
Foreachoperation0,ifcityxisalreadyrecaptured(thatis,thesame0xoperationappearsagain,print“Cityxisalreadyrecaptured.”
Foreachoperation1,ifcityxoryisnotrecapturedyet,print“Cityxoryisnotavailable.”otherwiseifKudocangofromcityxtocityyonlypassingtherecapturedcities,printtheshortestpath’slength;otherwiseprint“Nosuchpath.”
Youroutputformatshouldimitatethesampleoutput.Printablanklineaftereachtestcase.
SampleInputOutputfortheSampleInput
336
011
121
023
102
00
02
102
120
02
000
Case1:
City0or2isnotavailable.
3
Nosuchpath.
City2isalreadyrecaptured.
ProblemFFairytale
Itissaidthatinaschool’sunderground,thereisahugetreasurewhichcanmeetanydesireoftheowner.
TheSpyUnion(SUisveryinterestinthislegend.Aftermuchinvestigation,SUfinallygettheanswerandlettheyoungestspysneakintotheschool.That’swhySayaisnowhere.
Today,Sayafoundtheentranceeventually.
Sheenterstheentrance,andfoundherinafairy-taleworld.
“Welcome!
”saysafairy,“IamIvan.Myresponsibilityistoprotectthetreasure,andgiveittotheonewhohavetheabilitytoownit.”
ThenIvangivesSayathreeproblems.
Withyourhelp,Sayafinishedthefirstandthesecondproblem(ProblemHandI.Herecomesthethird.IfSayacansolvethisproblem,thetreasurebelongstoher.
Thereisabigmazeprotectingthetreasure.YoucanassumethemazeasanN*NmatrixwhileeachelementinthematrixmightbeN(North,S(South,W(WestorE(East.Atfirst,Sayaisattheelement(1,1–thenorth-westcorner,andthetreasureisat(N,N–thesouth-eastcorner.
Thedesignerhaveenchanttothismatrix,sothatthetreasuremightmovefromtimetotimerespectingthefollowingrules:
Supposethetreasureisinanelementwhichmarked