题目大意:
给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径
移动方向可以是上,下,左,右,前,后,六个方向
每移动一次就耗费一分钟,要求输出最快的走出时间。
不同L层的地图,相同RC坐标处是连通的
/*
Sample Input
3 4 5
S....
.###.
.##..
###.#
#####
#####
##.##
##...
#####
#####
#.###
####E
1 3 3
S##
#E#
###
0 0 0
Sample Output
Escaped in 11 minute(s).
Trapped!
*/
#include<cstdio>
#include<queue>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef struct point{
int x, y, z, r;
}point;
char str[31][31][31];
int arr[6][3] = {{0, 1, 0}, {0, -1, 0}, {1, 0, 0}, {-1, 0, 0},{0,0,1}, {0,0,-1}};
int bfs(point start, int l, int n, int m){
queue<point> que;
que.push(start);
point goal = {0,0,0,0}, p1 = {0,0,0,0};
while(!que.empty()){
p1 = que.front();
que.pop();
for(int k = 0; k < 6; k++){
goal.x = p1.x + arr[k][0];
goal.y = p1.y + arr[k][1];
goal.z = p1.z + arr[k][2];
goal.r = p1.r + 1;
if(str[goal.x][goal.y][goal.z] == 'E'){
return goal.r;
}
if(goal.x >= 0 && goal.x < l && goal.y >= 0 && goal.y < n && goal.z >= 0
&& goal.z < m && str[goal.x][goal.y][goal.z] != '#'){
str[goal.x][goal.y][goal.z] = '#';
que.push(goal);
}
}
}
return -1;
}
int main(){
int l, n, m, i, j;
while(scanf("%d%d%d", &l, &n, &m) && (l || m || n)){
getchar();
point start = {0,0,0,0};
int flag = 0;
for(int i = 0; i < l ; i++){
for(int j = 0; j < n; j++){
gets(str[i][j]);
if(!flag){
for(int k = 0; k < m; k++){
if(str[i][j][k] == 'S'){
start.x = i;
start.y = j;
start.z = k;
start.r = 0;
flag = 1;
}
}
}
}
getchar();
}
int re = bfs(start, l, n, m);
if(re != -1) printf("Escaped in %d minute(s).\n", re);
else printf("Trapped!\n");
}
}