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. C++的成员初始化列表和构造函数体(以前未知)

    成员的初始化列表和构造函数在对成员指定初值方面是不一样的.成员初始化列表是对成员初始化,而构造函数,是对成员赋值 成员初始化列表使用初始化的方式来为数据成员指定初值, 而构造函数的函数体是通过赋值的方 ...

  2. 牛客网第一场E题 Removal

    链接:https://www.nowcoder.com/acm/contest/139/E 来源:牛客网 Bobo has a sequence of integers s1, s2, ..., sn ...

  3. maven-assembly-plugin

    <build> <finalName>detail</finalName> <plugins> <plugin> <artifactI ...

  4. windows7时间同步设置

    1. 设置同步源 服务器修改为本车的104的ip地址,例如23车,手动输入 96.3.123.104 2. 设置同步周期. 注册表法 在“运行”框输入“Regedit”进入注册表编辑器 这种方法是通过 ...

  5. astah-professional-7_2_0安装

    astah-professional-7_2_0-1安装 1● 下载文件 2● 安装       replace   D:\Program\astahprofessional\inst\astah-p ...

  6. CAFFE 调试

    在Make.config 文件里将DEBUG=1的注释去掉,再make.可以用IDE如eclipse来import makefile工程.必要时按照IDE的提示将源文件cpp和对应的bin文件对应.

  7. pycuda安装 python<3.0

    cd pycudapython ./configure.py –cuda-root=/usr/local/cuda –cudadrv-lib-dir=/usr/lib –boost-inc-dir=/ ...

  8. zabbix_server.conf、zabbix_agentd.conf配置文件详解

    zabbix_server.conf配置文件详解 AlertScriptsPath 默认值:/usr/local/share/zabbix/alertscripts 说明:告警脚本目录 AllowRo ...

  9. Java Web(八) 事务,安全问题及隔离级别

    事务 什么是事务? 事务就是一组原子性的SQL查询,或者说是一个独立的工作单元. 事务的作用 事务在我们平常的CRUD(增删改查)操作当中也许不太常用, 但是如果我们有一种需求,一组操作中必须全部成功 ...

  10. learning scala ide tools install

    reference : https://www.jetbrains.com/help/idea/install-and-set-up-product.html env in ubuntu 16.04 ...