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!

题意:3维迷宫!“.”是路;“#”是墙,“E"进“S”出
这题的题目略有小坑;
注意几个地方:1.数组开到105以上;2.队列清空;
 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
int s[][][];
int vis[][][];
int r[]= {-,,,,,};
int c[]= {,,-,,,};
int h[]= {,,,,,-};
int ei,ej,ek;
struct node
{
int a,b,c;
int step;
};
node p,q;
void getit(int I,int J,int K)//输入并处理
{
char ch;
int i,j,k;
for(k=; k<K; k++)
{
for(i=; i<I; i++)
{
for(j=; j<J; j++)
{
scanf("%c",&ch);
if(ch=='.')
s[i][j][k]=-;
else if(ch=='E')
{
ei=i;
ej=j;
ek=k;
}
else if(ch=='S')
s[i][j][k]=;
}
getchar();
}
getchar();
}
}
void bfs(int ai,int aj, int ak,int step)//简单BFS
{
queue<node>que;
vis[ai][aj][ak]=;
int t;
p.a=ai;
p.b=aj;
p.c=ak;
p.step=step;
que.push(p);
while(!que.empty())
{
p=que.front();
que.pop();
for(t=; t<; t++)
{
q.a=p.a+r[t];
q.b=p.b+c[t];
q.c=p.c+h[t];
q.step=p.step+;
if(s[q.a][q.b][q.c]&&!vis[q.a][q.b][q.c])
{
if(s[q.a][q.b][q.c]==)
{
printf("Escaped in %d minute(s).\n",q.step);
return ;
}
que.push(q);
vis[q.a][q.b][q.c]=;
}
}
}
printf("Trapped!\n");
}
int main()
{ int I,J,K;
while(scanf("%d %d %d",&K,&I,&J)&&(I||J||K))
{
getchar();
memset(s,,sizeof(s));//置空
memset(vis,,sizeof(vis));
getit(I+,J+,K+);
bfs(ei,ej,ek,);
}
return ;
}

Dungeon Master(poj 2251)的更多相关文章

  1. Dungeon Master (POJ - 2251)(BFS)

    转载请注明出处: 作者:Mercury_Lc 地址:https://blog.csdn.net/Mercury_Lc/article/details/82693907 题目链接 题解:三维的bfs,一 ...

  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 /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)

    POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...

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

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

  5. 【POJ - 2251】Dungeon Master (bfs+优先队列)

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

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

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

  7. POJ 2251 Dungeon Master (非三维bfs)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 55224   Accepted: 20493 ...

  8. 【POJ 2251】Dungeon Master(bfs)

    BUPT2017 wintertraining(16) #5 B POJ - 2251 题意 3维的地图,求从S到E的最短路径长度 题解 bfs 代码 #include <cstdio> ...

  9. POJ 2251 Dungeon Master(多层地图找最短路 经典bfs,6个方向)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48380   Accepted: 18252 ...

随机推荐

  1. MapReduce实战:统计不同工作年限的薪资水平

    1.薪资数据集 我们要写一个薪资统计程序,统计数据来自于互联网招聘hadoop岗位的招聘网站,这些数据是按照记录方式存储的,因此非常适合使用 MapReduce 程序来统计. 2.数据格式 我们使用的 ...

  2. Python 记录(一)

    一开始没发现3.5与2.x版本的区别,导致浪费了很多时间在导包等问题上: 如: Pyhton2中的urllib2工具包,在Python3中分拆成了urllib.request和urllib.error ...

  3. asp.net下载文件的几种方法

    最近做东西遇到了下载相关的问题.在这里总结一下自己处理的方法. 1.以字节流的形式向页面输出数据以下载Excel为例子. string path=Server.MapPath("文件路径&q ...

  4. sqlserver 时间转换

    sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(), 时间一, ) 结果:-- :/*时间一般 ...

  5. 2017JAVA必读书籍

    1.深入理解Java虚拟机:JVM高级特性与最佳实践 2.Oracle查询优化改写技巧与案例 3.Effective Java 4.Spring3.x企业应用开发实战 5.Spring技术内幕:深入解 ...

  6. CentOS安装memcached及配置php的memcache扩展

    遇到的问题: 这个问题主要是linux服务器安装memcached服务后,phpinfo信息没有memcache扩展,所以主要是给php安装memcache扩展,教程中是安装memcache扩展,我认 ...

  7. jQuery实现页面滚动时顶部动态显示隐藏

    http://www.jqcool.net/jquery-scroll.html 另外headroom.js也行:http://www.bootcss.com/p/headroom.js/

  8. ASP.NET Excel数据导出数据库

    /// <summary> /// 根據gridview導出excel /// </summary> /// <param name="ctl"> ...

  9. PHPCMS(2)PHPCMS V9 环境搭建(转)

    转自:http://www.cnblogs.com/Braveliu/p/5072920.html PHPCMS V9的学习总结分为以下几点: [1]PHPCMS 简介 PHP原始为Personal ...

  10. sed 简明教程

    做个标记 http://coolshell.cn/articles/9104.html sed全名叫stream editor,流编辑器,用程序的方式来编辑文本,相当的hacker啊.sed基本上就是 ...