题目描述

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<cstring>
#include<queue>
using namespace std;
int t,n,m;
int dir[6][3] = {{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
char f[32][32][32];
struct p{int x, y, z, step;
} start, end1;
int bfs()
{p cur, nxt;f[start.x][start.y][start.z] = '#';start .step = 0;queue<p> q;q.push(start);while(q.size()){cur = q.front();q.pop();if(cur.x == end1.x && cur.y == end1.y && cur.z == end1.z)return cur.step;for(int i = 0; i < 6; i++){nxt.x = cur.x + dir[i][0];nxt.y = cur.y + dir[i][1];nxt.z = cur.z + dir[i][2];if(nxt.x >= 0 && nxt.x < t && nxt.y >=0 && nxt.y < n && nxt.z >= 0 && nxt.z < m && f[nxt.x][nxt.y][nxt.z] != '#'){f[nxt.x][nxt.y][nxt.z] = '#';nxt.step = cur.step + 1;q.push(nxt);}}}return -1;
}
int main()
{while(cin >> t >> n >> m){if(t == 0 && n == 0 && m == 0)break;getchar();for(int i = 0; i < t; i++){for(int j = 0; j < n; j++){for(int k = 0; k < m; k++){cin >> f[i][j][k];if(f[i][j][k] == 'S'){start.x = i;start.y = j;start.z = k;}if(f[i][j][k] == 'E'){end1.x = i;end1.y = j;end1.z = k;}}getchar();}if(i != t-1 ) getchar();}int ans = bfs();if(ans == -1) cout << "Trapped!" << endl;else printf("Escaped in %d minute(s).\n", ans);}return 0;
}

B - Dungeon Master相关推荐

  1. B - Dungeon Master POJ - 2251

    B - Dungeon Master POJ - 2251 题目: 逃离3D迷宫,n <=30 首先是dfs,算一下最坏情况共30层,每层有30*30的循环, 复杂度 3030*30 显然严重爆 ...

  2. POJ 2251 Dungeon Master(三维BFS求最短路径)

    3D dungeon 时间限制: 1 Sec  内存限制: 128 MB 提交: 2  解决: 2 [提交][状态][讨论版][命题人:201506020829][Edit] [TestData] 题 ...

  3. 信息学奥赛一本通(1248:Dungeon Master)

    1248:Dungeon Master 时间限制: 1000 ms         内存限制: 65536 KB 提交数: 8637     通过数: 3432 [题目描述] 这题是一个三维的迷宫题目 ...

  4. Dungeon Master 地下城大师(BFS进阶)

    题目链接:2251 -- Dungeon Master 知道你看不懂题(手动滑稽):友情链接. 题意:找到从S到E的最少步数的路径,输出该步数,不过有意思的是这个类似迷宫问题不是二维的,是一个三维迷宫 ...

  5. Dungeon Master(地牢大师、底下城主)三维bfs

    1253:Dungeon Master(地牢大师.底下城主) 要敢于变通 和普通bfs的区别,仅仅在于数组开三维+搜索方向多了上下(现在的搜索方向是 上下东南西北) bfs多组输入要记得清空队列 // ...

  6. Dungeon Master题解bfs

    Dungeon Master 题面翻译 题目描述 输入格式 输出格式 样例 #1 样例输入 #1 样例输出 #1 题解思路及TIME EXCEEDED问题 题解 超时题解(个人觉得没问题) 题面翻译 ...

  7. Dungeon Master(poj2251,bfs)

    http://poj.org/problem?id=2251 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=15203 Dun ...

  8. BFS - Dungeon Master

    Dungeon Master 题目链接: https://vjudge.net/problem/POJ-2251 题目: You are trapped in a 3D dungeon and nee ...

  9. (POJ - 2251)Dungeon Master(bfs)

    题目链接:2251 -- Dungeon Master (poj.org) 这是一个典型的bfs迷宫问题,只不过是三维的,唯一需要注意的就是输入要用cin,不要用scanf,因为有换行,其他没什么了, ...

  10. 1248:Dungeon Master

    1248:Dungeon Master 时间限制: 1000 ms         内存限制: 65536 KB 提交数: 11012     通过数: 4403 [题目描述] 这题是一个三维的迷宫题 ...

最新文章

  1. ibm750服务器维护,IBM 750服务器.PDF
  2. 自学python推荐书籍2019-入门必看 | 大佬们推荐的Python书单汇总
  3. python线下课程厦门_厦门python课程
  4. c语言ATM机文件储存账号密码,C语言实现_ATM自动取款机系统
  5. 2054无法登陆mysql_张虹亮'blog » ubuntu20.04安装mysql8之后,php5程序和phpmyadmin出现#2054 无法登录MySQL服务器的解决方案...
  6. 关于web页面中mata各种标签的解释
  7. MAC和IP地址伪造发包
  8. CS1.6自定义游戏中的H菜单和设置菜单,增加一键买枪功能
  9. 在themeforest购买主题获得激活码方法
  10. Ubuntu16.04安装ROS kinetic以及标定工具Kalibr流程
  11. 倍增算法入门 超详细解答+LCA+RMQ(ST表)+例题剖析
  12. 固网应用程序请重启计算机,固网USB打印服务器安装设置指引_固网 HP-1008MFP_办公打印评测试用-中关村在线...
  13. title在python中是什么意思_python – 在matplotlib中,title()和suptitle()之间有什么区别?...
  14. 苹果原壁纸高清_30张美女手机高清壁纸苹果手机安卓手机通用
  15. 最大公共子串LCS(Java实现)
  16. ARP欺骗:使用工具:arpspoof、driftnet和ettercap
  17. C语言判断一个数为超级素数,一个超级素数问题,时间限制是1秒钟,下面是题,哪位大触帮帮忙...
  18. java-net-php-python-26北京美食webAPP计算机毕业设计程序
  19. Matlab:Voronoi 图
  20. Orbit Downloader 1.5.4多国语言版

热门文章

  1. 华为内部狂转好文:有关大数据,看这一篇就够了
  2. GDAL源码剖析(五)之Python命令行程序
  3. 百度地图服务器不显示本地运行,百度地图定位成功,但地图不显示
  4. struts2中的constant配置详解
  5. meterpreter持久后门
  6. 全库检索包含某个值的表名和所在的列.
  7. String类的流程控制
  8. Python基础【day03】:字典(一)
  9. mysql主从复制读写分离
  10. [Java_kaikeba]java中堆和栈的区别(对象变量的理解)