• 问题描述:

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. 用三维数组来存地图,然后用广度优先搜索即可。
  • 代码:

  1. #include<cstdio>
  2. #include<queue>
  3. #include<cstring>
  4. #include<iostream>
  5. using namespace std;
  6. char a[][][];
  7. int l,r,c;
  8. int next[][]={{,,},{-,,},{,,},{,-,},{,,},{,,-}};
  9. struct node
  10. {
  11. int x;
  12. int y;
  13. int z;
  14. int step;
  15. }s,e,now,net;
  16.  
  17. int bfs()
  18. {
  19. queue<node> q;
  20. q.push(s);
  21. while(q.size())
  22. {
  23. now=q.front();
  24. if(now.x==e.x&&now.y==e.y&&now.z==e.z)
  25. return now.step;
  26. for(int i=;i<;i++)
  27. {
  28. net.x=now.x+next[i][];
  29. net.y=now.y+next[i][];
  30. net.z=now.z+next[i][];
  31. if(net.x>&&net.x<=l&&net.y>&&net.y<=r&&net.z>&&net.z<=c&&a[net.x][net.y][net.z]!='#')
  32. {
  33. a[net.x][net.y][net.z]='#';
  34. net.step=now.step+;
  35. q.push(net);
  36. }
  37. }
  38. q.pop();
  39. }
  40. return -;
  41. }
  42.  
  43. int main()
  44. {
  45. while(~scanf("%d%d%d",&l,&r,&c))
  46. {
  47. if(l==&&r==&&c==)break;
  48. for(int i=;i<=l;i++)
  49. {
  50. for(int j=;j<=r;j++)
  51. {
  52. for(int k=;k<=c;k++)
  53. {
  54. scanf(" %c",&a[i][j][k]);
  55. if(a[i][j][k]=='S')
  56. {
  57. s.x=i;
  58. s.y=j;
  59. s.z=k;
  60. s.step=;
  61. }
  62. if(a[i][j][k]=='E')
  63. {
  64. e.x=i;
  65. e.y=j;
  66. e.z=k;
  67. }
  68. }
  69. }
  70. }
  71. int ans=bfs();
  72. if(ans==-)printf("Trapped!\n");
  73. else printf("Escaped in %d minute(s).\n",ans);
  74. }
  75. return ;
  76. }

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

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

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

  2. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  3. 1253 Dungeon Master

    题目链接: http://noi.openjudge.cn/ch0205/1253/ http://poj.org/problem?id=2251 总时间限制: 1000ms  内存限制: 65536 ...

  4. NOI2.5 1253:Dungeon Master

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

  5. POJ - 2251 Dungeon Master(搜索)

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

  6. POJ - 2251 Dungeon Master (搜索)

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

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

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

  8. HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?

    这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others)  ...

  9. HDU 5652(二分+广搜)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/128683#problem/E 题目大意:给定一只含有0和1的地图,0代表可以走的格子,1代表不能走的格 子.之 ...

  10. nyoj 613 免费馅饼 广搜

    免费馅饼 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy ...

随机推荐

  1. 《C和指针》---指针

    内存和地址 计算机的内存由许多的位(bit)组成,每个位可以容纳值0或1. 由于一个位所能表示的范围太有限,所以通常许多位合成一组作为一个单元. 这些位置的每一个都被称为字节(byte),每个字节包含 ...

  2. webpack打包样式代码去重

    一.问题描述 控制台审查样式,同一个样式被导入很多遍,每调用一次@import "common.less";打包时都会多出一份类似的样式代码. 二.问题分析 补上... 三.解决方 ...

  3. 2019-2-14SQLserver中function函数和存储过程、触发器、CURSOR

    Sqlserver 自定义函数 Function使用介绍 前言:         在SQL server中不仅可以可以使用系统自带的函数(时间函数.聚合函数.字符串函数等等),还可以根据需要自定义函数 ...

  4. Ubuntu12.04 LTS 32位 安装ns-2.35

    ubuntu12.04lts 32-bit默认采用gcc 4.6和g++4.6,而ns的最新版本ns 2.3.5也采用了相同到版本,所以这方面不会有版本不同到问题 收回上面这句话..../valida ...

  5. 查看Linux系统软硬件信息

    查看Linux系统软硬件信息 查看计算机CPU信息 cat /proc/cpuinfo 查看文件系统信息 cat /proc/filesystems 查看主机中断信息 cat /proc/interr ...

  6. JTS相关资料和示例

    示例 JTS基本概念和使用 JTS Geometry之间的关系 JTS algorithm package

  7. js来判断设备类型

    function deviceType(){ var ua = navigator.userAgent; var agent = ["Android", "iPhone& ...

  8. AngularJS_简介、特性及基本使用_及其工作原理

    转自:angularJS 的工作原理 转自:通过<script>标签引入到 HTML 中,那么此时 Angular 就做为一个普通的 DOM 节点等待浏览器解析 当浏览器解析到这个节点时, ...

  9. python语法_字符串

    字符串 a = 'asdb' #双引号和打印号没区别, 操作 "abc"*2 打印两遍"abc"  #字符串 加* 重复打印字符串 “abc”[2:1] #切片 ...

  10. Mongodb 副本集+分片

    mongodb的分片功能是建立在副本集之上的,所以首先我们尝试着配置副本集. docker启动3个已经安装好mongo的镜像 # docker run -idt --name mongodb_01 m ...