链接:

http://poj.org/problem?id=2251

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 21370   Accepted: 8299

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

  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!

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <algorithm>
  6. #include <queue>
  7.  
  8. using namespace std;
  9.  
  10. #define N 35
  11.  
  12. struct node
  13. {
  14. int x, y, z, step;
  15. };
  16.  
  17. char Map[N][N][N];
  18. node e;
  19. int L, R, C;
  20. int dir[][]={{,,-},{,,},{,-,},{,,},{-,,},{,,}};
  21.  
  22. bool Judge(node s)
  23. {
  24. return s.x>= && s.x<L && s.y>= && s.y<R && s.z>= && s.z<C && Map[s.x][s.y][s.z]!='#';
  25. }
  26.  
  27. int BFS(node s)
  28. {
  29. node p;
  30. queue<node>Q;
  31. Q.push(s);
  32.  
  33. while(Q.size())
  34. {
  35. s = Q.front(), Q.pop();
  36.  
  37. if(s.x==e.x && s.y==e.y && s.z==e.z) return s.step;
  38.  
  39. for(int i=; i<; i++)
  40. {
  41. p.x = s.x + dir[i][];
  42. p.y = s.y + dir[i][];
  43. p.z = s.z + dir[i][];
  44. p.step = s.step + ;
  45.  
  46. if(Judge(p))
  47. {
  48. Q.push(p);
  49. Map[p.x][p.y][p.z] = '#';
  50. }
  51. }
  52. }
  53. return -;
  54. }
  55.  
  56. int main()
  57. {
  58. while(scanf("%d%d%d", &L, &R, &C), L+R+C)
  59. {
  60. node s;
  61.  
  62. memset(Map, , sizeof(Map));
  63.  
  64. for(int i=; i<L; i++)
  65. for(int j=; j<R; j++)
  66. {
  67. scanf("%s", Map[i][j]);
  68. for(int k=; k<C; k++)
  69. {
  70. if(Map[i][j][k]=='S')
  71. s.x=i, s.y=j, s.z=k, s.step=;
  72. if(Map[i][j][k]=='E')
  73. e.x=i, e.y = j, e.z=k;
  74. }
  75. }
  76.  
  77. int ans = BFS(s);
  78.  
  79. if(ans==-)
  80. printf("Trapped!\n");
  81. else
  82. printf("Escaped in %d minute(s).\n", ans);
  83. }
  84.  
  85. return ;
  86. }

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

  1. Dungeon Master poj 2251 dfs

    Language: Default Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16855 ...

  2. Dungeon Master POJ - 2251 (搜索)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48605   Accepted: 18339 ...

  3. Dungeon Master POJ - 2251(bfs)

    对于3维的,可以用结构体来储存,详细见下列代码. 样例可以过,不过能不能ac还不知道,疑似poj炸了, #include<iostream> #include<cstdio> ...

  4. Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索

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

  5. B - Dungeon Master POJ - 2251

    //纯bfs #include <iostream> #include <algorithm> #include <cstring> #include <cs ...

  6. kuangbin专题 专题一 简单搜索 Dungeon Master POJ - 2251

    题目链接:https://vjudge.net/problem/POJ-2251 题意:简单的三维地图 思路:直接上代码... #include <iostream> #include & ...

  7. 广搜+打表 POJ 1426 Find The Multiple

    POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Ac ...

  8. 广搜+输出路径 POJ 3414 Pots

    POJ 3414 Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13547   Accepted: 5718   ...

  9. POJ 2251 Dungeon Master(广搜,三维,简单)

    题目 简单的3d广搜,做法类似与 hdu 的 胜利大逃亡 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<str ...

随机推荐

  1. Angular 安装

    1.angular安装 npm  install -g angular 2. 显示angular安装路径 npm config ls 3. angular 双向绑定 <!DOCTYPE html ...

  2. NOIP2013 Day2

    1.积木大赛 https://www.luogu.org/problemnew/show/1969 这道题在考试时暴力得比较麻烦,导致只得了80分,t了两个点. 思路为寻找一个区间内高度大于0的最低点 ...

  3. WebDriverException: Message: 'phantomjs.exe' executable needs to be in PATH.

    本文转载自:http://blog.csdn.net/sinat_36764186/article/details/55520444 网上的某测试代码: from selenium import we ...

  4. HDU 1358 Period (kmp判断循环子串)

    Period Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  5. CFGym 100211J 题解

    一.题目 二.题意 给定一个字母表(最多也就是英文小写字母的前10个字母),一个交换表,两个字符串,判断字符串A能否通过交换表的交换方式变成字符串B. 三.思路 1.一开始,比赛时,我半模拟半记忆化地 ...

  6. [saiku] 简介、下载、安装和教程

    一.简介 Saiku成立于2008年,由Tom Barber和Paul Stoellberger研发. 最初叫做Pentaho分析工具,起初是基于OLAP4J库用GWT包装的一个前端分析工具. 经过多 ...

  7. 关于oracle数据库启动报ORA-01122,ORA-01110,ORA-01203错误的解决方法

    ORACLE 数据库空间裸设备出问题了,启动oracle失败,解决方法问题现象:     启动ORACLE的时候报如下的错误:        Database mounted.      ORA-01 ...

  8. 《OpenCL异构并行编程实战》第十二至十四章

    ▶ 第十二章,在其他语言中使用 OpenCL ● JOCL(Java Building for OpenCL),PyOpenCL ● 一个 PyOpenCL 的例子代码,需要 pyopencl 包 i ...

  9. Node爬虫之——使用async.mapLimit控制请求并发

    一般我们在写爬虫的时候,很多网站会因为你并发请求数太多当做是在恶意请求,封掉你的IP,为了防止这种情况的发生,我们一般会在代码里控制并发请求数,Node里面一般借助async模块来实现. 1. asy ...

  10. 4 ways to pass parameter from JSF page to backing bean

    As i know,there are 4 ways to pass a parameter value from JSF page to backing bean : Method expressi ...