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!

这个题目吧,是一个三维的搜索题目,题目不难,但是控制条件的地方一定要处理好,不然会爆内存,问的是最快什么时候逃出去,那么是广搜。

#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;
const int N=;
int h,m,n,s,x,y,z;
char a[N][N][N];
int dl[][]={{,,-},{,,},{,-,},{,,},{,,},{-,,}};
struct loc
{
int x,y,z,cnt;
loc(int x,int y,int z,int cnt):x(x),y(y),z(z),cnt(cnt){}
};
int pd(int x,int y,int z)
{
if(x<||x>h||y<||y>m||z<||z>n) return ;
else if(a[x][y][z]=='#')return ;
else if(a[x][y][z]=='E') return -;
else if(a[x][y][z]=='.') return ;
else return ;
}
int main()
{
queue<loc>dem;
while(cin>>h>>m>>n){
if(h==)break;
for(int i=;i<h;i++)
for(int j=;j<m;j++)
for(int k=;k<n;k++)
{
cin>>a[i][j][k];
if(a[i][j][k]=='S')x=i,y=j,z=k;
}
while(!dem.empty())dem.pop();
loc tem(x,y,z,);
dem.push(tem);
while(!dem.empty())
{
tem=dem.front();
a[tem.x][tem.y][tem.z]='#';
dem.pop();
for(int i=;i<;i++)
{
if(pd(tem.x+dl[i][],tem.y+dl[i][],tem.z+dl[i][])==-)
{
loc t(tem.x+dl[i][],tem.y+dl[i][],tem.z+dl[i][],tem.cnt+);
tem=t;
goto en;
//cout<<tem.x+dl[i][0]<<' '<<tem.y+dl[i][1]<<' '<<tem.z+dl[i][2]<<endl;
}
else if(pd(tem.x+dl[i][],tem.y+dl[i][],tem.z+dl[i][])==)
{
loc t(tem.x+dl[i][],tem.y+dl[i][],tem.z+dl[i][],tem.cnt+);
dem.push(t);
a[t.x][t.y][t.z]='#';
//cout<<tem.x+dl[i][0]<<' '<<tem.y+dl[i][1]<<' '<<tem.z+dl[i][2]<<endl;
}
}
} cout<<"Trapped!"<<endl;
continue;
en: printf("Escaped in %d minute(s).\n",tem.cnt);
}
}
 

最新文章

  1. [.net 面向对象程序设计深入](2)UML——在Visual Studio 2013/2015中设计UML用例图
  2. 【Cocos2d-x游戏开发】Cocos2d-x中的弱联网技术
  3. OpenGL ES 中的模板测试
  4. 关于ubuntu的sources.list总结
  5. 配置perl-cgi的运行环境,由于Active Perl安装在d:\perl
  6. Oracle创建,删除用户与表空间
  7. js 点击复制内容
  8. spring应用于web项目中
  9. 微信开发第8章 通过accesstoken将长连接转换为短链接
  10. WebView支持特效,页面内跳转(转载!)
  11. JSch - Java实现的SFTP(文件上传详解篇)(转)
  12. 前端学习笔记(zepto或jquery)—— 布局技巧(一)
  13. Volt 模块引擎与phalcon框架组合使用指南
  14. FFmpeg源代码简单分析:libswscale的sws_scale()
  15. WPF: 共享Grid宽度或高度的方法
  16. flutter Dynamic updates 热更新 版本更新
  17. OpenSSL生成RSA公私钥(java)
  18. openstack创建虚拟流程、各组件介绍
  19. NOIP 2016 蚯蚓 (luogu 2827 &amp; uoj 264) - 鬼畜的优化
  20. Interrouter Signals

热门文章

  1. string 从下标0 一直截到倒数第三位
  2. WPF 仿语音播放 自定义控件
  3. CSS也能计算:calc
  4. win7下delphi中的help文档问题
  5. windows/linux下如何更换Python的pip源
  6. Bug Bash in Personal Photo Experience 1/11/2016
  7. Kaggle入门——泰坦尼克号生还者预测
  8. NIO教程 ——检视阅读
  9. 5. git 过滤,让某文件夹里无法提交新添加的文件
  10. [YII2] 去除自带js,加载自己的JS,然后ajax(json)传值接值!