Description

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<cstdio>
#include<queue>
using namespace std;
int dx[]={-,,,,,};
int dy[]={,,-,,,};
int dz[]={,,,,,-};
char str[][][];
int l,r,c,i,j,k,ans,bx,bz,by;
struct stu
{
int x,y,z,step;
};
bool f(stu st)
{
if(st.x< || st.z< || st.y< || st.x>=r || st.y>=c || st.z>=l || str[st.z][st.x][st.y] =='#')
{
return false;
}
return true;
}
int bfs(int bz,int bx,int by)
{
str[bz][bx][by]='#';
int nx,ny,time,zz,xx,yy;
queue<stu> que;
stu st,next;
st.x=bx;
st.y=by;
st.z=bz;
st.step=;
que.push(st); while(!que.empty())
{ st=que.front();
que.pop(); xx=st.x;
yy=st.y;
zz=st.z;
time=st.step;
for(i = ;i < ; i++)
{
st.x=xx+dx[i];
st.y=yy+dy[i];
st.z=zz+dz[i];
if(!f(st))
{
continue;
}
if(str[st.z][st.x][st.y] == 'E')
{
return time+;
} st.step=time+;
que.push(st);
str[st.z][st.x][st.y]='#';
}
}
return ;
}
int main()
{
while(scanf("%d %d %d",&l,&r,&c)&&l&&r&&c)
{
for(i = ; i < l ; i++)
{
for(j = ; j < r ;j++)
{
scanf("%s",str[i][j]);
for(k = ; k < c ; k++)
{
if(str[i][j][k] == 'S')
{
bz=i;
bx=j;
by=k;
}
}
}
}
ans=bfs(bz,bx,by);
if(ans)
printf("Escaped in %d minute(s).\n",ans);
else
printf("Trapped!\n"); }
}

POJ 2251-Dungeon Master (三维空间求最短路径)的更多相关文章

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

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

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

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

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

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

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

  5. BFS POJ 2251 Dungeon Master

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

  6. POJ 2251 Dungeon Master (三维BFS)

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

  7. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  8. POJ 2251 Dungeon Master(三维空间bfs)

    题意:三维空间求最短路,可前后左右上下移动. 分析:开三维数组即可. #include<cstdio> #include<cstring> #include<queue& ...

  9. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  10. POJ - 2251 Dungeon Master 多维多方向BFS

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

随机推荐

  1. C# 中使用Image.FromFile(string path)后,提示该文件正在被另一进程使用XXX的问题

    C# 中使用Image.FromFile(string path)后,提示该文件正在被另一进程使用XXX的问题 C# 中使用Image.FromFile(string path)后,提示该文件正在被另 ...

  2. Jquery实现相对浏览器位置固定、悬浮

      <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></sc ...

  3. 【loj6034】「雅礼集训 2017 Day2」线段游戏

    #6034. 「雅礼集训 2017 Day2」线段游戏 内存限制:256 MiB 时间限制:1000 ms 标准输入输出 题目类型:传统 评测方式:Special Judge 上传者: 匿名 题目描述 ...

  4. Random Query CodeForces - 846F

    题目 翻译: 给出一个n个数字的数列a[1],...,a[n],f(l,r)表示使a[l],a[l+1],...,a[r]组成的新序列中的重复元素只保留一个后,剩下元素的数量(如果l>r,则在计 ...

  5. jmeter(二十)JMeter中返回Json数据的处理方法

    Json 作为一种数据交换格式在网络开发,特别是 Ajax 与 Restful 架构中应用的越来越广泛.而 Apache 的 JMeter 也是较受欢迎的压力测试工具之一,但是它本身没有提供对于 Js ...

  6. Coursera:一流大学免费在线课程平台

    https://www.coursera.org/ 微软联合创始人 Bill Gates 从公司退隐后,一直和妻子 Melinda 忙于公益事业.但离开 IT 圈并未改变他穿廉价衬衫和保持学习的习惯— ...

  7. 【学习笔记】深入理解js原型和闭包(11)——执行上下文栈

    继续上文的内容. 执行全局代码时,会产生一个执行上下文环境,每次调用函数都又会产生执行上下文环境.当函数调用完成时,这个上下文环境以及其中的数据都会被消除,再重新回到全局上下文环境.处于活动状态的执行 ...

  8. sql server 收缩日志文件

    USE 数据库名称 GO ALTER DATABASE 数据库名称 SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE 数据库名称 SET RECOV ...

  9. 洛谷 P2153 [SDOI2009]晨跑

    题目描述 Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十字路口和M条街 ...

  10. 1《数学之美》第1章 文字和语言 vs 数字和信息

    1<数学之美>第1章 文字和语言 vs 数字和信息