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 <cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
using namespace std; int h,m,n,res;
char ma[][][];
bool vis[][][];
int rx[]={,,,,,-};
int ry[]={,,,-,,};
int rz[]={,-,,,,}; struct node
{
int x,y,z;
int t;
}per;
int ex,ey,ez; bool judge(node a)
{
if(a.x>=&&a.x<m&&a.y>=&&a.y<n&&a.z>=&&a.z<h)
if(!vis[a.x][a.y][a.z])
if(ma[a.x][a.y][a.z]!='#')
return true;
return false;
} bool bfs()
{
queue<node>Q;
memset(vis,false,sizeof(vis));
Q.push(per);
vis[per.x][per.y][per.z]=true;
node tmp,next;
while(!Q.empty())
{
tmp=Q.front();
Q.pop();
if(tmp.x==ex&&tmp.y==ey&&tmp.z==ez)
{
res=tmp.t;
return true;
}
for(int i=;i<;i++)
{
next.x=tmp.x+rx[i];
next.y=tmp.y+ry[i];
next.z=tmp.z+rz[i];
next.t=tmp.t+;
if(judge(next))
{
Q.push(next);
vis[next.x][next.y][next.z]=true;
}
}
}
return false;
} int main()
{
while(~scanf("%d%d%d\n",&h,&m,&n)&&(h+m+n))
{
for(int q=;q<h;q++)
for(int i=;i<m;i++)
for(int j=;j<n;j++)
{
cin>>ma[i][j][q];
if(ma[i][j][q]=='S')
{
per.x=i;per.y=j;per.z=q;
per.t=;
}
else if(ma[i][j][q]=='E')
{
ex=i;ey=j;ez=q;
}
}
//
if(bfs()) printf("Escaped in %d minute(s).\n",res);
else printf("Trapped!\n");
}
return ;
}

												

poj 2251 Dungeon Master (BFS 三维)的更多相关文章

  1. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  2. POJ 2251 Dungeon Master【三维BFS模板】

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...

  3. poj 2251 Dungeon Master( bfs )

    题目:http://poj.org/problem?id=2251 简单三维 bfs不解释, 1A,     上代码 #include <iostream> #include<cst ...

  4. POJ 2251 Dungeon Master bfs 难度:0

    http://poj.org/problem?id=2251 bfs,把两维换成三维,但是30*30*30=9e3的空间时间复杂度仍然足以承受 #include <cstdio> #inc ...

  5. POJ 2251 Dungeon Master (BFS最短路)

    三维空间里BFS最短路 #include <iostream> #include <cstdio> #include <cstring> #include < ...

  6. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  7. BFS POJ 2251 Dungeon Master

    题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...

  8. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

  9. POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)

    POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...

随机推荐

  1. stl中的for_each() 函数的注意事项

    #include<iostream> using namespace std; #include"vector" #include"algorithm&quo ...

  2. leetcode-algorithms-1 two sum

    leetcode-algorithms-1 two sum Given an array of integers, return indices of the two numbers such tha ...

  3. 二十四、JAVA的NIO和IO的区别

    一.JAVA的NIO和IO 1.NIO:面向缓冲区(buffer)(分为非阻塞模式IO和阻塞模式IO)组成部分:Channels管道,Buffers缓冲区,Selectors选择器 2.IO:面向流( ...

  4. Linux下Tomcat项目启动报错

    Linux下Tomcat项目启动报错 org.springframework.beans.factory.CannotLoadBeanClassException: Error loading cla ...

  5. Java Web(一) 前言及体系结构

    Web应用程序 Web程序是什么 Web应用程序就是一般所说的网站,由服务器,客户端浏览器以及网络组成.但Web程序又不是一般意义的网站,一般的网站是提供信息服务,重在内容,程序往往比较简单,但商用的 ...

  6. shell 文件条件判断

    按照文件类型进行判断 '-b 文件' 判断该文件是否存在,并且是否为块设备文件(是块设备文件为真) '-c 文件' 判断该文件是否存在,并且是否为字符设备文件(是字符设备文件为真) '-d 文件' 判 ...

  7. vue数据请求显示loading图

    一般项目中,有时候会要求,你在数据请求的时候显示一张gif图片,然后数据加载完后,消失.这个,一般只需要在封装的axios中写入js事件即可.当然,我们首先需要在app.vue中,加入此图片.如下: ...

  8. day056 多表增加和查询

    今日总结: 多表的增删改查操作 多表操作 增 book id title book_detail publish author onetoone manytoone manytomany book_o ...

  9. 每天CSS学习之letter-spacing

    letter-spacing是CSS的一个属性,其作用是设置字符之间的距离.letter意为字符. 1.normal:规定字符之间没有额外的空间.该值是默认值.如下示例: p{ letter-spac ...

  10. Dll重定向(尚存否?)

    windows核心编程(第五版)的20.6节介绍了Dll重定向. 0x01  Dll重定向简介 产生Dll重定向原因: 应用程序 a.exe 依赖动态链接库 compoent.dll 1.0 版本.但 ...