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. jqgrid取所有行的值,jqgrid取行对应列(name)的值,jqgrid取多行值对应列转json的方法

    1.jqgrid取所有行的值(#gridTable指对应table的ID) var obj = $("#gridTable").jqGrid("getRowData&qu ...

  2. MySQL_插入更新 ON DUPLICATE KEY UPDATE

    平时我们在设计数据库表的时候总会设计 unique  或者 给表加上 primary key 的限制条件. 此时 插入数据的时候 ,经常会有这样的情况: 我们想向数据库插入一条记录: 若数据表中存在以 ...

  3. ActiveMQ producer不断发送消息,会导致broker内存耗尽吗?

    http://activemq.apache.org/my-producer-blocks.html 回答了这个问题: ActiveMQ 5.x 支持Message Cursors,它默认把消息从内存 ...

  4. Vue.js 引入外部js方法

    1.外部文件config.js 第一种写法 //常量的定义 const config = { baseurl:'http://172.16.114.5:8088/MGT2' } //函数的定义 fun ...

  5. Daily record-July

    July11. Nonsense! 胡说八道!2. Who cares! 谁管你呀!3. It's on me.. 我来付.4. It's a deal. 一言为定.5. I've done my b ...

  6. 网口扫盲二:Mac与Phy组成原理的简单分析

    1. general 下图是网口结构简图.网口由CPU.MAC和PHY三部分组成.DMA控制器通常属于CPU的一部分,用虚线放在这里是为了表示DMA控制器可能会参与到网口数据传输中. MAC(Medi ...

  7. linux操作系统及命令Part 1

    1.关于linux系统的安装与流程     (1)下载Vmware workstation 与 linux系统(centos版本.redhat版本.Ubuntu版本...)镜像. (2)详细安装见有道 ...

  8. unity中让摄像机移动到鼠标点击的位置和鼠标控制平移视角

    private Vector3 targetVector3; private float movespeed=0.5f; private bool IsOver = true; private Gam ...

  9. DoTween动画中的几种函数。

    1.transform.DOLocalMoveX(200, 1).From(true); 动画默认是从当前位置沿着X轴移动到x=200的位置. 加上Form变为从X=200的位置移动到当前位置,fro ...

  10. jdk重装后com.sun.tools.javac.Main is not on the classpath的问题 .

    在重装了JDk之后,在编译工程的时候出现如下错误: com.sun.tools.javac.Main is not on the classpath.Perhaps JAVA_HOME does no ...