Graphs 算法竞赛入门经典 刘汝佳Word文档下载推荐.docx

上传人:b****4 文档编号:17340494 上传时间:2022-12-01 格式:DOCX 页数:21 大小:42.68KB
下载 相关 举报
Graphs 算法竞赛入门经典 刘汝佳Word文档下载推荐.docx_第1页
第1页 / 共21页
Graphs 算法竞赛入门经典 刘汝佳Word文档下载推荐.docx_第2页
第2页 / 共21页
Graphs 算法竞赛入门经典 刘汝佳Word文档下载推荐.docx_第3页
第3页 / 共21页
Graphs 算法竞赛入门经典 刘汝佳Word文档下载推荐.docx_第4页
第4页 / 共21页
Graphs 算法竞赛入门经典 刘汝佳Word文档下载推荐.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

Graphs 算法竞赛入门经典 刘汝佳Word文档下载推荐.docx

《Graphs 算法竞赛入门经典 刘汝佳Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《Graphs 算法竞赛入门经典 刘汝佳Word文档下载推荐.docx(21页珍藏版)》请在冰豆网上搜索。

Graphs 算法竞赛入门经典 刘汝佳Word文档下载推荐.docx

SampleInput 

11

*

35

*@*@*

**@**

18

@@****@*

55

****@

*@@*@

*@**@

@@@*@

@@**@

00

SampleOutput 

1

2

657-Thedieiscast

InterGamesisahigh-techstartupcompanythatspecializesindevelopingtechnologythatallowsuserstoplaygamesovertheInternet.Amarketanalysishasalertedthemtothefactthatgamesofchanceareprettypopularamongtheirpotentialcustomers.BeitMonopoly,ludoorbackgammon,mostofthesegamesinvolvethrowingdiceatsomestageofthegame.

Ofcourse,itwouldbeunreasonableifplayerswereallowedtothrowtheirdiceandthenentertheresultintothecomputer,sincecheatingwouldbewaytoeasy.So,instead,InterGameshasdecidedtosupplytheiruserswithacamerathattakesapictureofthethrowndice,analyzesthepictureandthentransmitstheoutcomeofthethrowautomatically.

Forthistheydesperatelyneedaprogramthat,givenanimagecontainingseveraldice,determinesthenumbersofdotsonthedice.

Wemakethefollowingassumptionsabouttheinputimages.Theimagescontainonlythreedif-ferentpixelvalues:

forthebackground,thediceandthedotsonthedice.Weconsidertwopixels 

connected 

iftheyshareanedge-meetingatacornerisnotenough.Inthefigure,pixelsAandBareconnected,butBandCarenot.

Aset 

ofpixelsisconnectedifforeverypair(a,b)ofpixelsin 

S,thereisasequence 

in 

suchthat 

a1 

ak 

and 

ai 

ai+1 

areconnectedfor 

.

Weconsiderallmaximallyconnectedsetsconsistingsolelyofnon-backgroundpixelstobedice.`Maximallyconnected'

meansthatyoucannotaddanyothernon-backgroundpixelstothesetwithoutmakingitdis-connected.Likewiseweconsidereverymaximalconnectedsetofdotpixelstoformadot.

Theinputconsistsofpicturesofseveraldicethrows.Eachpicturedescriptionstartswithalinecontainingtwonumberswandh,thewidthandheightofthepicture,respectively.Thesevaluessatisfy 

Thefollowing 

linescontain 

characterseach.Thecharacterscanbe:

``.'

'

forabackgroundpixel,``*'

forapixelofadie,and``X'

forapixelofadie'

sdot.

Dicemayhavedifferentsizesandnotbeentirelysquareduetoopticaldistortion.Thepicturewillcontainatleastonedie,andthenumbersofdotsperdieisbetween1and6,inclusive.

Theinputisterminatedbyapicturestartingwith 

=0,whichshouldnotbeprocessed.

Foreachthrowofdice,firstoutputitsnumber.Thenoutputthenumberofdotsonthediceinthepicture,sortedinincreasingorder.

Printablanklineaftereachtestcase.

3015

..............................

...............*..............

...*****......****............

...*X***.....**X***...........

...*****....***X**............

...***X*.....****.............

...*****.......*..............

........***........******.....

.......**X****.....*X**X*.....

......*******......******.....

.....****X**.......*X**X*.....

Throw1

1224

784-MazeExploration

Amazeofrectangularroomsisrepresentedonatwodimensionalgridasillustratedinfigure1a.Eachpointofthegridisrepresentedbyacharacter.Thepointsofroomwallsaremarkedbythesamecharacterwhichcanbeanyprintablecharacterdifferentthan`*'

`_'

andspace.Infigure1thischaracteris`X'

.Alltheotherpointsofthegridaremarkedbyspaces.

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

XXXXXXX###X###X###XXX

XXXXX###########XXX

XXXXXXXXXXXXXXXXXXXXXXXXX#XXX#XXXXXXXXXX

XXXXXXXX###X###X###X###X

XX*XXX###############X

a)Initialmaze 

b)Paintedmaze

Figure1.Mazesofrectangularrooms

Allroomsofthemazeareequalsizedwithallwalls3pointswideand1pointthickasillustratedinfigure2.Inaddition,awallissharedonitsfulllengthbytheseparatedrooms.Theroomscancommunicatethroughdoors,whicharepositionedinthemiddleofwalls.Therearenooutdoordoors.

door

|

XXXX

X.Xmeasuredfromwithintheroom

door-...--wallsare3pointswide

X.X__

XXXXX|

|___wallsareonepointthick

Figure2.Aroomwith3doors

Yourproblemistopaintallroomsofamazewhichcanbevisitedstartingfromagivenroom,calledthe`startroom'

whichismarkedbyastar(`*'

)positionedinthemiddleoftheroom.Aroomcanbevisitedfromanotherroomifthereisadooronthewallwhichseparatestherooms.Byconvention,aroomispaintedifitsentiresurface,includingthedoors,ismarkedbythecharacter`#'

asshowninfigure1b.

Theprograminputisatextfilestructuredasfollows:

1.

Thefirstlinecontainsapositiveintegerwhichshowsthenumberofmazestobepainted.

2.

Therestofthefilecontainsthemazes.

Thelinesoftheinputfilecanbeofdifferentlength.Thetextwhichrepresentsamazeisterminatedbyaseparationlinefullofunderscores(`_'

).Thereareatmost30linesandatmost80charactersinalineforeachmaze

Theprogramreadsthemazesfromtheinputfile,paintsthemandwritesthepaintedmazesonthestandardoutput.

Theoutputtextofapaintedmazehasthesameformatasthatwhichhasbeenreadforthatmaze,includingtheseparationlines.Theexamplebelowillustratesasimpleinputwhichcontainsasinglemazeandthecorrespondingoutput.

XXXXXXXXX

XXX

X*X

XX

XXXXX

_____

X###X###X

X#######X

X###X

705-SlashMaze

Byfillingarectanglewithslashes(/)andbackslashes( 

),youcangeneratenicelittlemazes.Hereisanexample:

Asyoucansee,pathsinthemazecannotbranch,sothewholemazeonlycontainscyclicpathsandpathsenteringsomewhereandleavingsomewhereelse.Weareonlyinterestedinthecycles.Inourexample,therearetwoofthem.

Yourtaskistowriteaprogramthatcountsthecyclesandfindsthelengthofthelongestone.Thelengthisdefinedasthenumberofsmallsquaresthecycleconsistsof(theonesborderedbygraylinesinthepicture).Inthisexample,thelongcyclehaslength16andtheshortonelength4.

Theinputcontainsseveralmazedescriptions.Eachdescriptionbeginswithonelinecontainingtwointegers 

( 

),thewidthandtheheightofthemaze.Thenext 

linesrepresentthemazeitself,andcontain 

characterseach;

allthesecharacterswillbeeither``/"

or``\"

Theinputisterminatedbyatestcasebeginningwith 

=0.Thiscaseshouldnotbeprocessed.

Foreachmaze,firstoutputtheline``Maze#n:

where 

isthenumberofthemaze.Then,outputtheline``kCycles;

thelongesthaslength 

l.'

isthenumberofcyclesinthemazeand 

thelengthofthelongestofthecycles.Ifthemazedoesnotcontainanycycles,outputtheline``Therearenocycles."

Outputablanklineaftereachtestcase.

64

\//\\/

\///\/

//\\/\

\/\///

33

///

\//

\\\

Maze#1:

2Cycles;

thelongesthaslength16.

Maze#2:

Therearenocycles.

439-KnightMoves

Afriendofyouisdoingresearchonthe 

TravelingKnightProblem(TKP) 

whereyouaretofindtheshortestclosedtourofknightmovesthatvisitseachsquareofagivensetof 

squaresonachessboardexactlyonce.Hethinksthatthemostdifficultpartoftheproblemisdeterminingthesmallestnumberofknightmovesbetweentwogivensquaresandthat,onceyouhaveaccomplishedthis,findingthetourwouldbeeasy.

Ofcourseyouknowthatitisviceversa.Soyouofferhimtowriteaprogramthatsolvesthe"

difficult"

part.

Yourjobistowriteaprogramthattakestwosquares 

asinputandthendeterminesthenumberofknightmovesonashortestroutefrom 

to 

b.

InputSpecification

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

OutputSpecification

Foreachtestcase,printonelinesaying"

Togetfrom 

xx 

t

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

当前位置:首页 > 高等教育 > 医学

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

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