Ash Ketchum, has had a single dream his childhood - single aspiration for which
ID: 3636839 • Letter: A
Question
Ash Ketchum, has had a single dream his childhood - single aspiration for which he has perspired from as long as he can remember - the dream of becoming the most venerable Pokemon master on the face of the earth.
So this bright eyed young apprentice goes to Professor Oak of Pallet Town for guidance. There he gets his first and dearest pokemon, Pikachu. Professor Oak informs him that the Indigo Plateau Conference, the Indigo League general championship competition, will be held soon in Indigo Plateau. To emerge victorious from this championship is a dream of every pokemon master. But the road to this phenomenal glory is certainly not a cakewalk.
To participate in the championship, he must first defeat all the gym leaders in the Indigo League and earn batches from them. Professor Oak gives him a map, which shows the locations of the gym leaders he must defeat. But on his way, he must not enter the forests, populated by massive numbers of dangerous hypnotizing creatures like Drowzee and Hypno, or he would never be able to reach the competition in time.
With this Ash and Pikachu leave Pallet Town, to win the Indigo Plateau Conference. You need to help Ash calculate the smallest number of steps needed to reach Indigo Plateau from Pallet Town, while visiting all the gyms. Ash can only go up, down, left or right. Assume that Ash wins against every gym leader he fights.
The map will be a n x n grid as shown below (4 x 4 in this case):
I
G
F
F
G
G
F
F
G
P
P = Pallet Town
G = Gym
I = Indigo Plateau
F = Forest
Input
Your program must read the following data from the standard input. The first line specifies the grid size n, where n can be 2 through 30. Each of the following n lines contain n characters, each of which displays the item at that location. The empty squares are marked with '0' (the digit zero). All letters are in uppercase only. You can assume that there are atleast one and atmost 10 gyms in the map.
Example Input
4
I0G0
FFG0
GFFG
P000
Output
The output should be one line written to standard output, containing the smallest number of steps required to reach all gym leaders and then go to Indigo Plateau. If there is no way for Ash to reach all the gyms and Indigo Plateau, the output line should contain the number -1 instead. The line is terminated by a newline character.
Example Output
11
I
G
F
F
G
G
F
F
G
P
Explanation / Answer
hi...ihave solved itin my notebook...but its so big that i cannot write it here....you can rate me lifesaver and then i will mail it to you
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.