深度优先搜索Word文档下载推荐.docx

上传人:b****6 文档编号:16220258 上传时间:2022-11-21 格式:DOCX 页数:10 大小:42.92KB
下载 相关 举报
深度优先搜索Word文档下载推荐.docx_第1页
第1页 / 共10页
深度优先搜索Word文档下载推荐.docx_第2页
第2页 / 共10页
深度优先搜索Word文档下载推荐.docx_第3页
第3页 / 共10页
深度优先搜索Word文档下载推荐.docx_第4页
第4页 / 共10页
深度优先搜索Word文档下载推荐.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

深度优先搜索Word文档下载推荐.docx

《深度优先搜索Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《深度优先搜索Word文档下载推荐.docx(10页珍藏版)》请在冰豆网上搜索。

深度优先搜索Word文档下载推荐.docx

A,...

Output

Theoutputforeveryscenariobeginswithalinecontaining"

Scenario#i:

"

whereiisthenumberofthescenariostartingat1.Thenprintasinglelinecontainingthelexicographicallyfirstpaththatvisitsallsquaresofthechessboardwithknightmovesfollowedbyanemptyline.Thepathshouldbegivenonasinglelinebyconcatenatingthenamesofthevisitedsquares.Eachsquarenameconsistsofacapitalletterfollowedbyanumber.

Ifnosuchpathexist,youshouldoutputimpossibleonasingleline.

SampleInput

3

11

23

43

SampleOutput

Scenario#1:

A1

Scenario#2:

impossible

Scenario#3:

A1B3C1A2B4C2A3B1C3A4B2C4

Source

TUDProgrammingContest2005,Darmstadt,Germany

3083

Language:

ChildrenoftheCandyCorn

6545

2851

ThecornfieldmazeisapopularHalloweentreat.Visitorsareshowntheentranceandmustwanderthroughthemazefacingzombies,chainsaw-wieldingpsychopaths,hippies,andotherterrorsontheirquesttofindtheexit.

Onepopularmaze-walkingstrategyguaranteesthatthevisitorwilleventuallyfindtheexit.Simplychooseeithertherightorleftwall,andfollowit.Ofcourse,there'

snoguaranteewhichstrategy(leftorright)willbebetter,andthepathtakenisseldomthemostefficient.(Italsodoesn'

tworkonmazeswithexitsthatarenotontheedge;

thosetypesofmazesarenotrepresentedinthisproblem.)

Astheproprieterofacornfieldthatisabouttobeconvertedintoamaze,you'

dliketohaveacomputerprogramthatcandeterminetheleftandright-handpathsalongwiththeshortestpathsothatyoucanfigureoutwhichlayouthasthebestchanceofconfoundingvisitors.

Inputtothisproblemwillbeginwithalinecontainingasingleintegernindicatingthenumberofmazes.Eachmazewillconsistofonelinewithawidth,w,andheight,h(3<

=w,h<

=40),followedbyhlinesofwcharacterseachthatrepresentthemazelayout.Wallsarerepresentedbyhashmarks('

#'

),emptyspacebyperiods('

.'

),thestartbyan'

S'

andtheexitbyan'

E'

.

Exactlyone'

andone'

willbepresentinthemaze,andtheywillalwaysbelocatedalongoneofthemazeedgesandneverinacorner.Themazewillbefullyenclosedbywalls('

),withtheonlyopeningsbeingthe'

and'

.The'

willalsobeseparatedbyatleastonewall('

).

Youmayassumethatthemazeexitisalwaysreachablefromthestartpoint.

Foreachmazeintheinput,outputonasinglelinethenumberof(notnecessarilyunique)squaresthatapersonwouldvisit(includingthe'

)for(inorder)theleft,right,andshortestpaths,separatedbyasinglespaceeach.Movementfromonesquaretoanotherisonlyallowedinthehorizontalorverticaldirection;

movementalongthediagonalsisnotallowed.

2

88

########

#......#

#.####.#

#...#..#

#S#E####

95

#########

#.#.#.#.#

S.......E

3755

17179

SouthCentralUSA2006

3009Curling2.0

6807

2841

OnPlanetMM-21,aftertheirOlympicgamesthisyear,curlingisgettingpopular.Buttherulesaresomewhatdifferentfromours.Thegameisplayedonanicegameboardonwhichasquaremeshismarked.Theyuseonlyasinglestone.Thepurposeofthegameistoleadthestonefromthestarttothegoalwiththeminimumnumberofmoves.

Fig.1showsanexampleofagameboard.Somesquaresmaybeoccupiedwithblocks.Therearetwospecialsquaresnamelythestartandthegoal,whicharenotoccupiedwithblocks.(Thesetwosquaresaredistinct.)Oncethestonebeginstomove,itwillproceeduntilithitsablock.Inordertobringthestonetothegoal,youmayhavetostopthestonebyhittingitagainstablock,andthrowagain.

Fig.1:

Exampleofboard(S:

start,G:

goal)

Themovementofthestoneobeysthefollowingrules:

∙Atthebeginning,thestonestandsstillatthestartsquare.

∙Themovementsofthestonearerestrictedtoxandydirections.Diagonalmovesareprohibited.

∙Whenthestonestandsstill,youcanmakeitmovingbythrowingit.Youmaythrowittoanydirectionunlessitisblockedimmediately(Fig.2(a)).

∙Oncethrown,thestonekeepsmovingtothesamedirectionuntiloneofthefollowingoccurs:

oThestonehitsablock(Fig.2(b),(c)).

▪Thestonestopsatthesquarenexttotheblockithit.

▪Theblockdisappears.

oThestonegetsoutoftheboard.

▪Thegameendsinfailure.

oThestonereachesthegoalsquare.

▪Thestonestopsthereandthegameendsinsuccess.

∙Youcannotthrowthestonemorethan10timesinagame.Ifthestonedoesnotreachthegoalin10moves,thegameendsinfailure.

Fig.2:

Stonemovements

Undertherules,wewouldliketoknowwhetherthestoneatthestartcanreachthegoaland,ifyes,theminimumnumberofmovesrequired.

WiththeinitialconfigurationshowninFig.1,4movesarerequiredtobringthestonefromthestarttothegoal.TherouteisshowninFig.3(a).Noticewhenthestonereachesthegoal,theboardconfigurationhaschangedasinFig.3(b).

Fig.3:

ThesolutionforFig.D-1andthefinalboardconfiguration

Theinputisasequenceofdatasets.Theendoftheinputisindicatedbyalinecontainingtwozerosseparatedbyaspace.Thenumberofdatasetsneverexceeds100.

Eachdatasetisformattedasfollows.

thewidth(=w)andtheheight(=h)oftheboard

Firstrowoftheboard

...

h-throwoftheboard

Thewidthandtheheightoftheboardsatisfy:

2<

=w<

=20,1<

=h<

=20.

Eachlineconsistsofwdecimalnumbersdelimitedbyaspace.Thenumberdescribesthestatusofthecorrespondingsquare.

0

vacantsquare

1

block

2

startposition

3

goalposition

ThedatasetforFig.D-1isasfollows:

66

100210

110000

000003

000000

100001

011111

Foreachdataset,printalinehavingadecimalintegerindicatingtheminimumnumberofmovesalongaroutefromthestarttothegoal.Iftherearenosuchroutes,print-1instead.Eachlineshouldnothaveanycharacterotherthanthisnumber.

21

32

66

100210

110000

000003

000000

100001

61

112113

102113

121

201111111113

131

2011111111113

00

1

4

-1

10

Japan2006Domestic

1321棋盘问题

10000K

15034

7428

在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。

要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。

输入含有多组测试数据。

每组数据的第一行是两个正整数,nk,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。

n<

=8,k<

=n

当为-1-1时表示输入结束。

随后的n行描述了棋盘的形状:

每行有n个字符,其中#表示棋盘区域,.表示空白区域(数据保证不出现多余的空白行或者空白列)。

对于每一组数据,给出一行输出,输出摆放的方案数目C(数据保证C<

2^31)。

#.

.#

44

...#

..#.

.#..

#...

-1-1

蔡错@pku

2251

DungeonMaster

11510

4465

Youaretrappedina3Ddungeonandneedtofindthequickestwayout!

Thedungeoniscomposedofunitcubeswhichmayormaynotbefilledwithrock.Ittakesoneminutetomoveoneunitnorth,south,east,west,upordown.Youcannotmovediagonallyandthemazeissurroundedbysolidrockonallsides.

Isanescapepossible?

Ifyes,howlongwillittake?

Theinputconsistsofanumberofdungeons.EachdungeondescriptionstartswithalinecontainingthreeintegersL,RandC(alllimitedto30insize).

Listhenumberoflevelsmakingupthedungeon.

RandCarethenumberofrowsandcolumnsmakinguptheplanofeachlevel.

ThentherewillfollowLblocksofRlineseachcontainingCcharacters.Eachcharacterdescribesonecellofthedungeon.Acellfullofrockisindicatedbya'

andemptycellsarerepresentedbya'

.Yourstartingpositionisindicatedby'

andtheexitbytheletter'

.There'

sasingleblanklineaftereachlevel.InputisterminatedbythreezeroesforL,RandC.

Eachmazegeneratesonelineofoutput.Ifitispossibletoreachtheexit,printalineoftheform

Escapedinxminute(s).

wherexisreplacedbytheshortesttimeittakestoescape.

Ifitisnotpossibletoescape,printtheline

Trapped!

345

S....

.###.

.##..

###.#

#####

##.##

##...

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

当前位置:首页 > PPT模板 > 艺术创意

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

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