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. [NOIP2018校模拟赛]T1聚会 party

    题目链接: 聚会 分析: 设每个点到1号点的距离为dist_{i},每个点的权值为x_{i},目标点到1号点的距离为dist,权值为x,那么对于每一次查询,我们讨论三种情况: ① 目标家庭在区间左边( ...

  2. 模拟+贪心 URAL 1804 The Machinegunners in a Playoff

    题目传送门 题意:A队和B队踢球,已知一场比赛A和B的得分情况,问A最小再得几分就能胜利还有最多能的几分还能给B队一丝翻盘的希望.规则如下: 1. 总分数相等的情况下,在客场得分高的获胜,如果还相等, ...

  3. 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges

    题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...

  4. linux下实现多台服务器同步文件(inotify-tools+rsync实时同步文件安装和配置)

    inotify-tools+rsync实时同步文件安装和配置 注:转载https://www.linuxidc.com/Linux/2012-06/63624.htm

  5. Hu矩

    close all; clear all; I1=imread('lena.bmp'); angle=; T=[cos(angle),sin(angle),;-sin(angle),cos(angle ...

  6. java自带线程池

    1. newSingleThreadExecutor 创建一个单线程的线程池.这个线程池只有一个线程在工作,也就是相当于单线程串行执行所有任务.如果这个唯一的线程因为异常结束,那么会有一个新的线程来替 ...

  7. Docker DOC

    Docker DOC docker是提供给开发或管理人员的容器化部署项目工具 在linux上运行docker 常用命令 docker 安装 #先更新yum yum update; #设置docker仓 ...

  8. Git-往返github和本地

    将GitHub仓库Test弄到本地 本地新建文件夹Test 右击运行gitbash 在gitbash中输入git init 在github 仓库选择clone or download 复制链接http ...

  9. 《精通css》笔记

    第2章    选择器,注释 1.要知道常用选择器(id选择器,类选择器,类型选择器,后代选择器,伪类选择器(文档结构之外)) 通用选择器(*{    }) 高级选择器(子选择器,相邻同胞选择器,属性选 ...

  10. 关于Android发送短信获取送达报告的问题

    最近公司开发一个项目,要求app能够发送短信并获取送达报告.这本不是一个什么难题,实现这一功能的代码一搜一大把,那么这么简单的一个问题,为什么我要在这里提出来呢?那是因为我在写代码的时候掉入了一个坑, ...