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<iostream>
# include<cstdio>
# include<algorithm>
# include<cstring>
# include<queue>
using namespace std;
struct node
{
int x,y,z,t;
node(int a,int b,int c,int d):x(a),y(b),z(c),t(d){}
bool operator < (const node &a) const {
return t>a.t;
}
};
char p[][][],vis[][][];
int l,r,c;
int d[][]={{,,},{,,-},{,,},{-,,},{,,},{,-,}};
void bfs(int sx,int sy,int sz)
{
priority_queue<node>q;
memset(vis,,sizeof(vis));
vis[sx][sy][sz]='';
q.push(node(sx,sy,sz,));
while(!q.empty())
{
node u=q.top();
q.pop();
if(p[u.x][u.y][u.z]=='E'){
printf("Escaped in %d minute(s).\n",u.t);
return ;
}
for(int i=;i<;++i){
int nx=u.x+d[i][],ny=u.y+d[i][],nz=u.z+d[i][];
if(nx>=&&nx<r&&ny>=&&ny<c&&nz>=&&nz<l&&!vis[nx][ny][nz]&&p[nx][ny][nz]!='#'){
vis[nx][ny][nz]='';
q.push(node(nx,ny,nz,u.t+));
}
}
}
printf("Trapped!\n");
}
int main()
{
while(scanf("%d%d%d",&l,&r,&c),l+r+c)
{
int sx,sy,sz;
for(int k=;k<l;++k){
for(int i=;i<r;++i){
for(int j=;j<c;++j){
cin>>p[i][j][k];
if(p[i][j][k]=='S')
sx=i,sy=j,sz=k;
}
}
}
bfs(sx,sy,sz);
}
return ;
}
代码如下:

POJ-2251 Dungeon Master (BFS模板题)的更多相关文章

  1. poj 2251 Dungeon Master( bfs )

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

  2. POJ 2251 Dungeon Master bfs 难度:0

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

  3. poj 2251 Dungeon Master (BFS 三维)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

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

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

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

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

  6. BFS POJ 2251 Dungeon Master

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

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

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

  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 ...

  10. POJ 2251 Dungeon Master (三维BFS)

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

随机推荐

  1. zookeeper与卡夫卡集群搭建

    首先这片博客没有任何理论性的东西,只是详细说明kafka与zookeeper集群的搭建过程,需要三台linux服务器. java环境变量设置 zookeeper集群搭建 kafka集群搭建 java环 ...

  2. bzoj1642 / P2889 [USACO07NOV]挤奶的时间Milking Time

    P2889 [USACO07NOV]挤奶的时间Milking Time 普通的dp 休息时间R其实就是把结束时间后移R个单位而已.但是终点也需要后移R位到n+R. 每个时间段按起始时间排序,蓝后跑一遍 ...

  3. 20145225《网络对抗》Exp6 信息搜集与漏洞扫描

    基础问题回答 哪些组织负责DNS,IP的管理: 全球根服务器均由美国政府授权的ICANN统一管理,负责DNS和IP地址管理.全球一共有5个地区性注册机构:ARIN(北美地区业务),RIPE(负责欧洲地 ...

  4. 20145339顿珠 Exp5 MSF基础应用

    20145339顿珠 Exp5 MS08_067漏洞测试 实验过程 IP地址:192.168.1.104 虚拟机ip:192.168.1.102 在控制台内使用search ms08_067查看相关信 ...

  5. Pandas fillna('Missing')

    https://blog.csdn.net/donghf1989/article/details/51167083/ .使用0替代缺失值(当然你可以用任意一个数字代替NaN) df.fillna(0) ...

  6. JVM堆内存调优

    堆大小设置JVM 中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-bit)限制:系统的可用虚拟内存限制:系统的可用物理内存限制.32位系统下,一般限制在1.5G~2G:64为操作 ...

  7. Unity 之 Vector3

    class Variables one  指向(0,0,0) zero 指向(1,1,1) right指向 x轴的方向 Up   指向 y轴的方向 forward  指向 z轴的方向

  8. Wireshark无法解析OpenFlow配置协议 解决方法

    在使用wireshark对OpenFlow交换机与FlowVisor的通信过程进行抓包分析的时候,在其选项中有openflow_v1选项,但Wireshark竟无法解析OpenFlow协议. 在查阅相 ...

  9. 初探 Yii2 的测试模式 index-test.php

    有没有发现高级版每个应用的 web 目录下有两个入口文件,一个index.php 一个 index-test.php通过init.bat可以切换到调试模式和产品模式,这两个模式相信同学们都很熟悉了,那 ...

  10. C++ 在容器A中查找最后出现的容器B中的元素,并返回iterator(find_end)

    #include <iostream> // cout #include <algorithm> // find_end #include <vector> // ...