资源描述:
《Graphs算法竞赛入门经典刘汝佳》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、TheGeoSurvCompgeologicsurveycompanyisresponsiblefordetectingundergroundoildeposits.GeoSurvCompworkswithonelargerectangularregionoflandatatime,andcreatesagridthatdividesthelandintonumeroussquareplots.Itthenanalyzeseachplotseparately,usingsensingequipmenttod
2、eterminewhetherornottheplotcontainsoil.Aplotcontainingoiliscalledapocket.Iftwopocketsareadjacent,thentheyarepartofthesameoildeposit.Oildepositscanbequitelargeandmaycontainnumerouspockets.Yourjobistodeterminehowmanydifferentoildepositsarecontainedinagrid.In
3、put Theinputfilecontainsoneormoregrids.Eachgridbeginswithalinecontainingm and n,thenumberofrowsandcolumnsinthegrid,separatedbyasinglespace.If m =0itsignalstheendoftheinput;otherwise and .Followingthisare m linesof n characterseach(notcountingtheend-of-lin
4、echaracters).Eachcharactercorrespondstooneplot,andiseither`*',representingtheabsenceofoil,or`@',representinganoilpocket.Output Foreachgrid,outputthenumberofdistinctoildeposits.Twodifferentpocketsarepartofthesameoildepositiftheyareadjacenthorizontally,verti
5、cally,ordiagonally.Anoildepositwillnotcontainmorethan100pockets.SampleInput 11*35*@*@***@***@*@*18@@****@*55****@*@@*@*@**@@@@*@@@**@00SampleOutput 0122657-ThedieiscastInterGamesisahigh-techstartupcompanythatspecializesindevelopingtechnologythatallowsusers
6、toplaygamesovertheInternet.Amarketanalysishasalertedthemtothefactthatgamesofchanceareprettypopularamongtheirpotentialcustomers.BeitMonopoly,ludoorbackgammon,mostofthesegamesinvolvethrowingdiceatsomestageofthegame.Ofcourse,itwouldbeunreasonableifplayerswere
7、allowedtothrowtheirdiceandthenentertheresultintothecomputer,sincecheatingwouldbewaytoeasy.So,instead,InterGameshasdecidedtosupplytheiruserswithacamerathattakesapictureofthethrowndice,analyzesthepictureandthentransmitstheoutcomeofthethrowautomatically.Forth
8、istheydesperatelyneedaprogramthat,givenanimagecontainingseveraldice,determinesthenumbersofdotsonthedice.Wemakethefollowingassumptionsabouttheinputimages.Theimagescontainonlythreedif-ferentpixelvalues:fortheba