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

  1. 3 4 5
  2. S....
  3. .###.
  4. .##..
  5. ###.#
  6.  
  7. #####
  8. #####
  9. ##.##
  10. ##...
  11.  
  12. #####
  13. #####
  14. #.###
  15. ####E
  16.  
  17. 1 3 3
  18. S##
  19. #E#
  20. ###
  21.  
  22. 0 0 0

Sample Output

  1. Escaped in 11 minute(s).
  2. Trapped!
  3.  
  4. 三维bfs水题,但鉴于自己好久没有做bfs,忘记了vis数组放哪里和取值,最最重要的是中间一行代码写错了,害我debug半天
    bfs模板题
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<queue>
  4. #include<cstring>
  5. using namespace std;
  6. int dx[]={,,-,,,},dy[]={,-,,,,},dz[]={,,,,,-};
  7. int t,n,m,sx,sy,sz,ex,ey,ez,vis[][][];
  8. char mapn[][][];
  9. struct node{
  10. int x,y,z,step;
  11. };
  12. void bfs(){
  13. node p;
  14. p.x = sx,p.y = sy,p.z = sz;
  15. vis[sx][sy][sz] = ;
  16. p.step = ;
  17. queue<node> q;
  18. q.push(p);
  19. while(!q.empty()){
  20. node tmp = q.front();
  21. q.pop();
  22. if(tmp.x == ex && tmp.y == ey && tmp.z == ez){
  23. cout << "Escaped in " << tmp.step << " minute(s)." << endl;
  24. return;
  25. }
  26. for(int i=;i<;i++){
  27. int xx = tmp.x + dx[i];
  28. int yy = tmp.y + dy[i];
  29. int zz = tmp.z + dz[i];
  30. if(mapn[xx][yy][zz] != '#' && xx> && xx<=t && yy> && yy<=n && zz> && zz<=m && !vis[xx][yy][zz]){
  31. node tp;
  32. tp.x = xx;
  33. tp.y = yy;
  34. tp.z = zz;
  35. tp.step = tmp.step + ;//这一行代码,开始写成了tp.step++;
  36. vis[xx][yy][zz] = ;
  37. q.push(tp);
  38. }
  39. }
  40. }
  41. cout << "Trapped!" << endl;
  42. }
  43. int main(){
  44. while(cin >> t >> n >> m){
  45. if(t == || n == || m == ){
  46. break;
  47. }
  48. memset(vis,,sizeof(vis));
  49. for(int i=;i<=t;i++){
  50. for(int j=;j<=n;j++){
  51. for(int k=;k<=m;k++){
  52. cin >> mapn[i][j][k];
  53. if(mapn[i][j][k] == 'S'){
  54. sx = i,sy = j,sz = k;
  55. }
  56. if(mapn[i][j][k] == 'E'){
  57. ex = i,ey = j,ez = k;
  58. }
  59. }
  60. }
  61. }
  62. bfs();
  63. }
  64. return ;
  65. }

Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索的更多相关文章

  1. 迷宫问题 POJ - 3984 [kuangbin带你飞]专题一 简单搜索

    定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...

  2. Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索

    Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...

  3. 棋盘问题 POJ - 1321 [kuangbin带你飞]专题一 简单搜索

    在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C. ...

  4. [kuangbin带你飞]专题一 简单搜索(回顾)

    A - 棋盘问题 POJ - 1321 注意条件:不能每放一个棋子,就标记一行和一列,我们直接枚举每一行就可以了. AC代码: #include<iostream> #include< ...

  5. [kuangbin带你飞]专题一 简单搜索

            ID Origin Title 454 / 1008 Problem A POJ 1321 棋盘问题   328 / 854 Problem B POJ 2251 Dungeon Ma ...

  6. [kuangbin带你飞]专题一 简单搜索 - B - Dungeon Master

    #include<iostream> #include<cstdio> #include<string> #include<vector> #inclu ...

  7. [kuangbin带你飞]专题一 简单搜索 题解报告

    又重头开始刷kuangbin,有些题用了和以前不一样的思路解决.全部题解如下 点击每道题的标题即可跳转至VJ题目页面. A-棋盘问题 棋子不能摆在相同行和相同列,所以我们可以依此枚举每一行,然后标记每 ...

  8. [kuangbin带你飞]专题一 简单搜索 x

    A - 棋盘问题 POJ - 1321 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋 ...

  9. [kuangbin带你飞]专题一 简单搜索 - E - Find The Multiple

    //Memory Time //2236K 32MS #include<iostream> using namespace std; ]; //保存每次mod n的余数 //由于198的余 ...

随机推荐

  1. NYOJ 53 最少步数

    题      目    http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=58 思路借鉴   DFS-Deep First Search-深度优先 ...

  2. Struts完成用户新增操作

    点击新增客户出现该页面并完成前后台交互 代码逻辑分析: jsp 页面部分代码 <TABLE id=table_1 style="DISPLAY: none" cellSpac ...

  3. Qt Socket 收发图片——图像拆包、组包、粘包处理

    之前给大家分享了一个使用python发图片数据.Qt server接收图片的Demo.之前的Demo用于传输小字节的图片是可以的,但如果是传输大的图片,使用socket无法一次完成发送该怎么办呢?本次 ...

  4. LR有的JMeter也有之一“参数化”

    酝酿了几天,一直想写点JMeter的东西,算是对学习东西的一个整理.:) 恩,一直觉得自己领悟能力不强,别人写的东西总要看老半天也不懂.好吧!一惯的傻瓜的方式(大量的截图+参数说明)嘻嘻. 参数化:简 ...

  5. python异常处理-异常捕获-抛出异常-断言-自定义异常-UDP通信-socketserver模块应用-3

    异常捕获 异常:程序在运行过程中出现了不可预知的错误,并且该错误没有对应的处理机制,那么就会以异常的形式表现出来 影响:整个程序无法再正常运行 异常的结构 异常的类型 NameError 异常的信息 ...

  6. Oracle GoldenGate mysql To Kafka上车记录

    一.前言 首先要学习一下ogg的所有进程,看着这张图来学习   Manager进程是GoldenGate的控制进程,运行在源端和目标端上.它主要作用有以下几个方面:启动.监控.重启Goldengate ...

  7. 头部姿态估计 - Android

    概括 通过Dlib获得当前人脸的特征点,然后通过旋转平移标准模型的特征点进行拟合,计算标准模型求得的特征点与Dlib获得的特征点之间的差,使用Ceres不断迭代优化,最终得到最佳的旋转和平移参数. A ...

  8. android ——多线程编程

    1.定义一个线程只需要新建一个类继承自Thread.然后重写run()方法,并在里面编写耗时逻辑即可: class MyThread extends Thread{ public void run() ...

  9. jmeter界面字体修改

    实际应用中发现,同样是win10系统,显示器屏幕尺寸大小不同,jmeter界面字体展示也不一样,标准屏幕还可以,大屏幕下不能自动适应屏幕大小放大而且还变的更小.在查询解决方法时,发现有朋友出现类似情况 ...

  10. Kafka之Producer

    通过https://www.cnblogs.com/tree1123/p/11243668.html 已经对consumer有了一定的了解.producer比consumer要简单一些. 一.旧版本p ...