Write a program that, given a map with treasures and obstacles, indicates if is possible or not to arrive to any treasure from a given initial position. The allowed movements are horizontal or vertical, but not diagonal. If it is necessary, passing over the treasures is allowed.
Input starts with the number of rows
and the number of columns
of the map.
rows follow with
characters each one. A dot indicates an empty position, a
’X’ indicates an obstacle, and a ’t’ indicates
a treasure. Finally, a pair of numbers
and
indicates the initial row and column (both of them starting with 1)
where your program must start to look for the treasures. You can suppose
that
,
that
,
that
will be between 1 and
,
that
will be between 1 and
,
and that the initial position will be always in an empty position.
Your program must print "1" or "0"
depending on if it possible or not to arrive to any treasure.
The simplest way to solve this exercise does not use any queue.
Input
7 6 ..t... ..XXX. ...... tX..X. .X..Xt .XX... ..t... 5 3
Output
1
Input
4 10 ..t...X... .....X..t. XXXXX.X... .......X.t 4 1
Output
0
Input
5 7 ....... .XXXXXt .X...Xt .X.X.XX ...X.Xt 5 5
Output
1