浙江大学acm.docx

上传人:b****6 文档编号:8494450 上传时间:2023-01-31 格式:DOCX 页数:22 大小:124.13KB
下载 相关 举报
浙江大学acm.docx_第1页
第1页 / 共22页
浙江大学acm.docx_第2页
第2页 / 共22页
浙江大学acm.docx_第3页
第3页 / 共22页
浙江大学acm.docx_第4页
第4页 / 共22页
浙江大学acm.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

浙江大学acm.docx

《浙江大学acm.docx》由会员分享,可在线阅读,更多相关《浙江大学acm.docx(22页珍藏版)》请在冰豆网上搜索。

浙江大学acm.docx

浙江大学acm

<++++++++++++++++++++++BreadthFirstSearchProblemsonZOJ+++++++++++++++++++++++++>

ZOJProblemSet-1091nightMoves

TimeLimit:

1Second    MemoryLimit:

32768KB

AfriendofyouisdoingresearchontheTravelingKnightProblem(TKP)whereyouaretofindtheshortestclosedtourofknightmovesthatvisitseachsquareofagivensetofnsquaresonachessboardexactlyonce.Hethinksthatthemostdifficultpartoftheproblemisdeterminingthesmallestnumberofknightmovesbetweentwogivensquaresandthat,onceyouhaveaccomplishedthis,findingthetourwouldbeeasy.

Ofcourseyouknowthatitisviceversa.Soyouofferhimtowriteaprogramthatsolvesthe"difficult"part.

Yourjobistowriteaprogramthattakestwosquaresaandbasinputandthendeterminesthenumberofknightmovesonashortestroutefromatob.

InputSpecification

Theinputfilewillcontainoneormoretestcases.Eachtestcaseconsistsofonelinecontainingtwosquaresseparatedbyonespace.Asquareisastringconsistingofaletter(a-h)representingthecolumnandadigit(1-8)representingtherowonthechessboard.

OutputSpecification

Foreachtestcase,printonelinesaying"Togetfromxxtoyytakesnknightmoves.".

SampleInput

e2e4

a1b2

b2c3

a1h8

a1h7

h8a1

b1c3

f6f6

SampleOutput

Togetfrome2toe4takes2knightmoves.

Togetfroma1tob2takes4knightmoves.

Togetfromb2toc3takes2knightmoves.

Togetfroma1toh8takes6knightmoves.

Togetfroma1toh7takes5knightmoves.

Togetfromh8toa1takes6knightmoves.

Togetfromb1toc3takes1knightmoves.

Togetfromf6tof6takes0knightmoves.

Source:

UniversityofUlmLocalContest1996

ZOJProblemSet–1103HikeonaGraph

TimeLimit:

1Second    MemoryLimit:

32768KB

"HikeonaGraph"isagamethatisplayedonaboardonwhichanundirectedgraphisdrawn.Thegraphiscompleteandhasallloops,i.e.foranytwolocationsthereisexactlyonearrowbetweenthem.Thearrowsarecoloured.Therearethreeplayers,andeachofthemhasapiece.Atthebeginningofthegame,thethreepiecesareinfixedlocationsonthegraph.Inturn,theplayersmaydoamove.Amoveconsistsofmovingone'sownpiecealonganarrowtoanewlocationontheboard.Thefollowingconstraintisimposedonthis:

thepiecemayonlybemovedalongarrowsofthesamecolourasthearrowbetweenthetwoopponents'pieces.

Inthesixties("makelovenotwar")aone-personvariantofthegameemerged.Inthisvariantonepersonmovesallthethreepieces,notnecessarilyoneaftertheother,butofcourseonlyoneatatime.Goalofthisgameistogetallpiecesontothesamelocation,usingasfewmovesaspossible.Findoutthesmallestnumberofmovesthatisnecessarytogetallthreepiecesontothesamelocation,foragivenboardlayoutandstartingpositions.

InputSpecification

Theinputfilecontainsseveraltestcases.Eachtestcasestartswiththenumbern.Inputisterminatedbyn=0.Otherwise,1<=n<=50.Thenfollowthreeintegersp1,p2,p3with1<=pi<=ndenotingthestartinglocationsofthegamepieces.Thecoloursofthearrowsaregivennextasam×mmatrixofwhitespace-separatedlower-caseletters.Theelementmijdenotesthecolourofthearrowbetweenthelocationsiandj.Sincethegraphisundirected,youcanassumethematrixtobesymmetrical.

OutputSpecification

Foreachtestcaseoutputonasinglelinetheminimumnumberofmovesrequiredtogetallthreepiecesontothesamelocation,ortheword"impossible"ifthatisnotpossibleforthegivenboardandstartinglocations.

SampleInput

3123

rbr

bbb

rbr

2122

yg

gy

0

SampleOutput

2

impossible

Source:

UniversityofUlmLocalContest2000

ZOJProblemSet–1136Multiple

TimeLimit:

10Seconds    MemoryLimit:

32768KB

aprogramthat,givenanaturalnumberNbetween0and4999(inclusively),andMdistinctdecimaldigitsX1,X2..XM(atleastone),findsthesmalleststrictlypositivemultipleofNthathasnootherdigitsbesidesX1,X2..XM(ifsuchamultipleexists).

Theinputfilehasseveraldatasetsseparatedbyanemptyline,eachdatasethavingthefollowingformat:

Onthefirstline-thenumberN

Onthesecondline-thenumberM

OnthefollowingMlines-thedigitsX1,X2..XM.

Foreachdataset,theprogramshouldwritetostandardoutputonasinglelinethemultiple,ifsuchamultipleexists,and0otherwise.

Anexampleofinputandoutput:

Input

22

3

7

0

1

2

1

1

Output

110

0

Source:

SoutheasternEurope2000

ZOJProblemSet–1301TheNewVilla

TimeLimit:

1Second    MemoryLimit:

32768KB    SpecialJudge

Mr.Blackrecentlyboughtavillainthecountryside.Onlyonethingbothershim:

althoughtherearelightswitchesinmostrooms,thelightstheycontrolareofteninotherroomsthantheswitchesthemselves.Whilehisestateagentsawthisasafeature,Mr.Blackhascometobelievethattheelectricianswereabitabsent-minded(toputitmildly)whentheyconnectedtheswitchestotheoutlets.

Onenight,Mr.Blackcamehomelate.Whilestandinginthehallway,henotedthatthelightsinallotherroomswereswitchedoff.Unfortunately,Mr.Blackwasafraidofthedark,soheneverdaredtoenteraroomthathaditslightsoutandwouldneverswitchoffthelightsoftheroomhewasin.

Aftersomethought,Mr.Blackwasabletousetheincorrectlywiredlightswitchestohisadvantage.Hemanagedtogettohisbedroomandtoswitchoffalllightsexceptfortheoneinthebedroom.

Youaretowriteaprogramthat,givenadescriptionofavilla,determineshowtogetfromthehallwaytothebedroomifonlythehallwaylightisinitiallyswitchedon.Youmayneverenteradarkroom,andafterthelastmove,alllightsexceptfortheoneinthebedroommustbeswitchedoff.Ifthereareseveralpathstothebedroom,youhavetofindtheonewhichusesthesmallestnumberofsteps,where``movefromoneroomtoanother'',``switchonalight''and``switchoffalight''eachcountasonestep.

Input

Theinputcontainsseveralvilladescriptions.Eachvillastartswithalinecontainingthreeintegersr,d,ands.risthenumberofroomsinthevilla,whichwillbeatmost10.disthenumberofdoors/connectionsbetweentheroomsandsisthenumberoflightswitchesinthevilla.Theroomsarenumberedfrom1tor;roomnumber1isthehallway,roomnumberristhebedroom.

Thislineisfollowedbydlinescontainingtwointegersiandjeach,specifyingthatroomiisconnectedtoroomjbyadoor.Thenfollowslinescontainingtwointegerskandleach,indicatingthatthereisalightswitchinroomkthatcontrolsthelightinrooml.

Ablanklineseparatesthevilladescriptionfromthenextone.Theinputendswithavillahavingr=d=s=0,whichshouldnotbeprocessed.

Output

Foreachvilla,firstoutputthenumberofthetestcase(`Villa#1',`Villa#2',etc.)inalineofitsown.

IfthereisasolutiontoMr.Black'sproblem,outputtheshortestpossiblesequenceofstepsthatleadshimtohisbedroomandonlyleavesthebedroomlightswitchedon.(Outputonlyoneshortestsequenceifyoufindmorethanone.)Adheretotheoutputformatshowninthesamplebelow.

Ifthereisnosolution,outputalinecontainingthestatement`Theproblemcannotbesolved.'

Outputablanklineaftereachtestcase.

SampleInput

334

12

13

32

12

13

21

32

212

21

11

12

000

SampleOutput

Villa#1

Theproblemcanbesolvedin6steps:

-Switchonlightinroom2.

-Switchonlightinroom3.

-Movetoroom2.

-Switchofflightinroom1.

-Movetoroom3.

-Switchofflightinroom2.

Villa#2

Theproblemcannotbesolved.

Source:

SouthwestEurope1996

ZOJProblemSet–1310Robot

TimeLimit:

1Second    MemoryLimit:

32768KB

TheRobotMovingInstituteisusingarobotintheirlocalstoretotransportdifferentitems.Ofcoursetherobotshouldspendonlytheminimumtimenecessarywhentravellingfromoneplaceinthestoretoanother.Therobotcanmoveonlyalongastraightline(track).Alltracksformarectangulargrid.Neighbouringtracksareonemeterapart.ThestoreisarectangleNxMmetersanditisentirelycoveredbythisgrid.Thedistanceofthetrackclosesttothesideofthestoreisexactlyonemeter.Therobothasacircularshapewithdiameterequalto1.6meter.Thetrackgoesthroughthecenteroftherobot.Therobotalwaysfacesnorth,south,westoreast.Thetracksareinthesouth-northandinthewest-eastdirections.Therobotcanmoveonlyinthedirectionitfaces.Thedirectioninwhichitfacescanbechangedateachtrackcrossing.Initiallytherobotstandsatatrackcrossing.Theobstaclesinthestoreareformedfrompiecesoccupying1mx1montheground.Eachobstacleiswithina1x1squareformedbythetracks.Themovementoftherobotiscontrolledbytwocommands.ThesecommandsareGOandTURN.

TheGOcommandhasoneintegerparameternin{1,2,3}.Afterreceivingthiscommandtherobotmovesnmetersinthedirectionitfaces.

TheTURNcommandhasoneparameterwhichiseitherleftorright.Afterreceivingthiscommandtherobotchangesitsorientationby90ointhedirectionindicatedbytheparameter.

Theexecutionofeachcommandlastsonesecond.

HelpresearchersofRMItowriteaprogramwhichwilldeterminetheminimaltimeinwhichtherobotcanmovefromagivenstartingpointtoagivendestination.

Input

Theinputconsistsofblocksoflines.ThefirstlineofeachblockcontainstwointegersM<=50andN<=50separatedbyonespace.IneachofthenextMlinesthereareNnumbersoneorzeroseparatedbyonespace.Onerepresentsobstaclesandzerorepresentsemp

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1