POJ 2251 Dungeon Master
Description
You are trapped in a dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.
Is an escape possible? If yes, how long will it take?
Input
The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers and (all limited to in size).
L is the number of levels making up the dungeon.
and are the number of rows and columns making up the plan of each level.
Then there will follow blocks of lines each containing characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a ‘#’ and empty cells are represented by a ‘.’. Your starting position is indicated by ‘S’ and the exit by the letter ‘E’. There’s a single blank line after each level. Input is terminated by three zeroes for and .
Output
Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
Escaped in x minute(s).
where is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
Trapped!
Sample Input
3 4 5
S/./././.
/./#/#/#/.
/./#/#/./.
/#/#/#/./#
/#/#/#/#/#
/#/#/#/#/#
/#/#/./#/#
/#/#/././.
/#/#/#/#/#
/#/#/#/#/#
/#/./#/#/#
/#/#/#/#E
1 3 3
S/#/#
/#E/#
/#/#/#
0 0 0
Sample Output
Escaped in 11 minute(s).
Trapped!
Translation
走迷宫,每走一步要花费一分钟,地图上标记为’#‘的点不可走,标记为’.'的点可走,问至少花费几分钟走出迷宫。
Idea
数据范围较小,经典的走迷宫问题。
需要注意的问题如下:
- 用数组标记访问
- 判断可走条件
- 定义位移矢量
Code
1 |
|