Académique Documents
Professionnel Documents
Culture Documents
TCS:CodeVitaCodingArena
TCSNextStepTCSCareerswww.tcs.com
Logout
WelcomeCHIDVILASPUTTA
Home
CodingArena
05 57 13
hr
min
sec
F
Rules&Regulations
Problem:BaseCamp
Three friends set out to explore a remote area. They choose a safe place and make it their Base Camp. To speed up
explorationtimetheydecidetoworkindependently.Atanygivenpoint,eitheroneormoreofthemcansetouttoexplore
the area. They set a protocol that after exploring the area they must meet back at the Base Camp in the evening and
exchangenotes.
LaunchCodeEditor
The remote area consists of accessible and inaccessible pieces of land. Being ordinary humans, they must walk only the
accessible piece of land. In order to maximize their exploration time, each one is interested in knowing about a shortest
pathbacktothebasecamp.
Giventhattheareaunderexplorationisarrangedinformofarectangulargrid,helptheexplorerstochalkoutashortest
path back to the base camp. Properties of a rectangle can be used as heuristic in computing distance between their
positionsandtheBaseCamp.Yourtaskistofindoutandmarktheshortestpathforeachexplorerandprinteachpathasa
separategrid.
Theinputandoutputspecificationsectionsdescribehowinputswillbeprovidedonconsoleandhowoutputisexpectedback
onconsole.
InputFormat:
1.Firstlineofinputcontainsgriddimensions<rows,columns>delimitedbyspacecharacter
2.Nextrowsnumberoflinescontaincolumnnumberofcharacters
3.Validcharactersare{s,d,w,},where
a.srepresentsthelocationoftheexplorer
b.drepresentsthelocationofthebasecamp
c.wrepresentsinaccessibleregion
d.representsaccessibleregion
4.Endofinputismarkedby1character
OutputFormat:
1.Numberofgridsintheoutputshouldbesameasnumberofexplorersi.e.'s'charactersintheinputgrid
2.Eachoutputgridshouldbeofthesamedimensionastheinputgrid
3.Eachoutputgridshouldcontainpathfromexplorerlocationstobasecamplocationd
4.Iftherearemorethanoneexplorers,explorerwithsmallest<row,column>valueshouldbeprintedfirstinthe
output.Nextsmallestexplorerlocationshouldbeprintednextfollowedbythelastexplorergrid.
5.Firstexplorerpathshouldbemarkedby'a'character,secondby'b'characterandthirdby'c'character
6.The's'characterinthegridmustbereplacedby{a,borc}whicheverisappropriateforthegivenexplorer
7.The's'character(s)inthegridmustbereplacedby''characterforotherexplorer(s)
8.Outputgridsmustbeseparatedbyablankline
9.Seeexamplesectionforbetterunderstanding
Constraints:
1.Itisguaranteedthattherewillalwaysbeexactlyoneshortestpathforoneexplorerfromagivenlocation
SampleInputandOutput
SNo. Input
44
wd
ww
www
ss
1
Output
wd
waw
waww
a
wd
wbw
wbww
bb
a
a
https://www.tcscodevita.com/CodevitaV5/problemstart.jsp
1/2
7/22/2016
TCS:CodeVitaCodingArena
a
d
44
ss
sd
1
b
b
b
d
cccd
Explanationforsampleinputandoutput1:
Figure1.
Figure2.
Note:Theoutputformatshownaboveisforunderstandingpurposesuchthatithighlightstheshortestpathbetweenthe
explorerandthebasecamp.Theexamplesinabovetabledepictsoutputintextformatasyouwillberequiredtoprovide.
Note:
Pleasedonotusepackageandnamespaceinyourcode.Forobjectorientedlanguagesyourcodeshouldbewritteninone
class.
Note:
ParticipantssubmittingsolutionsinClanguageshouldnotusefunctionsfrom<conio.h>/<process.h>asthesefilesdonot
existingcc
Note:
ForCandC++,returntypeofmain()functionshouldbeint.
2016TataConsultancyServicesLimited.AllRightsReserved.
SubmitAnswer
I,CHIDVILASPUTTAconfirmthattheanswersubmittedismyown.
Browse...
2016TataConsultancyServicesLimited.AllRightsReserved. InAssociationwith
https://www.tcscodevita.com/CodevitaV5/problemstart.jsp
|PrivacyPolicy
2/2