|
<p> |
|
Standard mazes lose their mystery as one grows older. But throw in some lasers, |
|
and suddenly you've got yourself a recipe for cross-generational appeal. |
|
The object in any maze is to find your way from your starting point to some |
|
goal. In a <em>Laser Maze</em> you must additionally contend with laser turrets. |
|
</p> |
|
|
|
<p> |
|
A laser turret is a stationary pillar that both blocks your movement and fires |
|
lasers from one side. Every time you take a step (either up, down, left, or right), |
|
every laser turret in the maze then |
|
rotates 90 degrees clockwise, and then shoots a momentary laser blast in the direction that it |
|
is facing. Needless to say, if you find yourself in the path of one of these |
|
lasers, you won't be around long enough to find a way out. A wall is a stationary pillar that |
|
blocks your movement, but does not fire lasers. |
|
</p> |
|
|
|
<p> |
|
Lasers are powerful, but they do not pass through walls or laser turrets. |
|
The laser turrets respond to your movements, so you can't stand still and wait |
|
for the turrets to turn. If you reach the goal, but are immediately shot by a |
|
laser, your efforts will have been in vain, so make sure you reach the goal |
|
safely. |
|
</p> |
|
|
|
<h3>Input</h3> |
|
|
|
<p> |
|
Input begins with an integer <strong>T</strong>, the number of mazes |
|
you'll explore. For each maze, there is first a line containing two integers, |
|
<strong>M</strong> and <strong>N</strong>, the height and width of the maze, |
|
respectively. The next <strong>M</strong> lines contain <strong>N</strong> |
|
characters each, describing the maze: |
|
</p> |
|
|
|
<p> |
|
. (empty space) <br /> |
|
# (wall) <br /> |
|
S (starting position) <br /> |
|
G (goal) <br /> |
|
< > ^ v (laser turrets) <br /> |
|
</p> |
|
|
|
<p> |
|
The four symbols for laser turrets signify turrets that are initially pointing |
|
left, right, up, or down respectively before you take your first step. |
|
</p> |
|
|
|
|
|
<h3>Output</h3> |
|
|
|
<p> |
|
For the <em>i</em>th maze, print a line containing "Case #<em>i</em>: " followed by |
|
the smallest number of steps necessary to get to the exit without being |
|
hit by a laser, or the string "impossible'' if there is no way to reach the |
|
goal safely. |
|
</p> |
|
|
|
|
|
<h3>Constraints</h3> |
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 100 <br /> |
|
1 ≤ <strong>M</strong>, <strong>N</strong> ≤ 100 <br /> |
|
Each maze will contain exactly one 'S' and exactly one 'G'. |
|
</p> |
|
|
|
|
|
|
|
|