1815: 2.5-1253:Dungeon Master
Description
You are trapped in a 3D 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 L, R and C (all limited to 30 in size).
L is the number of levels making up the dungeon.
R and C are the number of rows and columns making up the plan of each level.
Then there will follow L blocks of R lines each containing C 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 L, R and C.
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 x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
Trapped!
Sample Input Copy
3 4 5
S....
.###.
.##..
###.#
#####
#####
##.##
##...
#####
#####
#.###
####E
1 3 3
S##
#E#
###
0 0 0
Sample Output Copy
Escaped in 11 minute(s).
Trapped!
HINT
翻译:
你在层数为L,每层R行C列个小房间的构成的迷宫里。每分钟你可以从当前的房间前往上、下、左、右、前或后相邻的房间(不能前往障碍或迷宫外部),请你求出走到出口要多少分钟。
多组测试数据,每组第一行为三个整数L,R,C(1<=L,R,C<=30),接下来共L*(R+1)行,每R行描述一层楼,用.表示房间,#表示障碍,S表示入口,E表示出口,每层楼描述完后有一个空行。L=R=C=0表示输入结束。
对于每组测试数据输出一行结果,如果最少用x分钟可以走到迷宫的出口,输出“Escaped in x minute(s).”,如果不能到达出口,输出“Trapped!”。