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

3 4 5
S....
.###.
.##..
###.# #####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0

Sample Output

Escaped in 11 minute(s).
Trapped! 开三维数组用BFS求。
 #include<cstdio>
#include<queue>
using namespace std;
int dx[]={-,,,,,};
int dy[]={,,-,,,};
int dz[]={,,,,,-};
char str[][][];
int l,r,c,i,j,k,ans,bx,bz,by;
struct stu
{
int x,y,z,step;
};
bool f(stu st)
{
if(st.x< || st.z< || st.y< || st.x>=r || st.y>=c || st.z>=l || str[st.z][st.x][st.y] =='#')
{
return false;
}
return true;
}
int bfs(int bz,int bx,int by)
{
str[bz][bx][by]='#';
int nx,ny,time,zz,xx,yy;
queue<stu> que;
stu st,next;
st.x=bx;
st.y=by;
st.z=bz;
st.step=;
que.push(st); while(!que.empty())
{ st=que.front();
que.pop(); xx=st.x;
yy=st.y;
zz=st.z;
time=st.step;
for(i = ;i < ; i++)
{
st.x=xx+dx[i];
st.y=yy+dy[i];
st.z=zz+dz[i];
if(!f(st))
{
continue;
}
if(str[st.z][st.x][st.y] == 'E')
{
return time+;
} st.step=time+;
que.push(st);
str[st.z][st.x][st.y]='#';
}
}
return ;
}
int main()
{
while(scanf("%d %d %d",&l,&r,&c)&&l&&r&&c)
{
for(i = ; i < l ; i++)
{
for(j = ; j < r ;j++)
{
scanf("%s",str[i][j]);
for(k = ; k < c ; k++)
{
if(str[i][j][k] == 'S')
{
bz=i;
bx=j;
by=k;
}
}
}
}
ans=bfs(bz,bx,by);
if(ans)
printf("Escaped in %d minute(s).\n",ans);
else
printf("Trapped!\n"); }
}

最新文章

  1. 会话控制(session、cookie)
  2. Mac OS 快捷键
  3. 趣谈PHP 多态
  4. HDU1166-敌兵布阵(线段树)
  5. Android中 判断是平板还是手机
  6. java/php/c#版rsa签名以及java验签实现--转
  7. Android Studio,使用外部模拟器作为生成app调试的模拟器
  8. Hibernate HQL中的子查询
  9. PHPCMS v9.5.6 通杀getshell(前台)
  10. 关于jmeter读取CSV文件的详细设置
  11. Ansoftmaxwell15.0
  12. mobike
  13. JS获取宽度高度大集合
  14. MongoDB数据库基本命令
  15. 关于UIPageViewController那些事
  16. python简单实现队列和栈push、pop操作
  17. ILP32、ILP64、LP64、LLP64、64位系统
  18. 聊聊Java中的拆箱和装箱操作
  19. 2016年第七届蓝桥杯C/C++B组省赛题目解析
  20. 题目1003:A+B

热门文章

  1. 使用Git分布式版本控制系统
  2. Hdu 4725 The Shortest Path in Nya Graph (spfa)
  3. 洛谷p2922[USACO08DEC]秘密消息Secret Message
  4. Keepalived+Nginx实现Nginx的高可用
  5. C#基础学习5
  6. js中关于this的理解
  7. sql子查询的例子
  8. python工具之exccel模板生成报表
  9. JVM初探
  10. UISegmentedControl去掉背景色与UIScrollView联动