Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 17555   Accepted: 6835

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!

Source

 
bfs 六个方向直接乱搞就好
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 31
const int inf=0x7fffffff; //无限大
int visited[maxn][maxn][maxn];
struct node
{
int x;
int y;
int z;
int cnt;
};
int dx[]={,-,,,,};
int dy[]={,,,-,,};
int dz[]={,,,,,-};
int main()
{
int n,m,k;
string s;
while(cin>>n>>m>>k)
{
if(n==&&m==&&k==)
break;
memset(visited,,sizeof(visited));
node sb;
node sb2;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
cin>>s;
for(int t=;t<k;t++)
{
if(s[t]=='S')
{
sb.x=i;
sb.y=j;
sb.z=t;
sb.cnt=;
}
if(s[t]=='E')
{
sb2.x=i;
sb2.y=j;
sb2.z=t;
}
if(s[t]=='#')
{
visited[i][j][t]=;
}
}
}
}
queue<node> q;
q.push(sb);
visited[sb.x][sb.y][sb.z]=;
int flag=;
while(!q.empty())
{
node now=q.front();
for(int i=;i<;i++)
{
node next;
next.x=now.x+dx[i];
next.y=now.y+dy[i];
next.z=now.z+dz[i];
next.cnt=now.cnt+;
if(next.x<||next.x>=n||next.y<||next.y>=m||next.z<||next.z>=k)
continue;
if(visited[next.x][next.y][next.z])
continue;
visited[next.x][next.y][next.z]=;
if(next.x==sb2.x&&next.y==sb2.y&&next.z==sb2.z)
flag=next.cnt;
if(flag>)
break;
q.push(next);
}
if(flag>)
break;
q.pop();
}
if(flag>)
printf("Escaped in %d minute(s).\n",flag);
else
cout<<"Trapped!"<<endl; }
return ;
}

hdu 2251 Dungeon Master bfs的更多相关文章

  1. poj 2251 Dungeon Master( bfs )

    题目:http://poj.org/problem?id=2251 简单三维 bfs不解释, 1A,     上代码 #include <iostream> #include<cst ...

  2. poj 2251 Dungeon Master (BFS 三维)

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

  3. POJ 2251 Dungeon Master bfs 难度:0

    http://poj.org/problem?id=2251 bfs,把两维换成三维,但是30*30*30=9e3的空间时间复杂度仍然足以承受 #include <cstdio> #inc ...

  4. POJ 2251 Dungeon Master (BFS最短路)

    三维空间里BFS最短路 #include <iostream> #include <cstdio> #include <cstring> #include < ...

  5. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  6. POJ 2251 Dungeon Master (三维BFS)

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

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

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

  8. BFS POJ 2251 Dungeon Master

    题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...

  9. poj 2251 Dungeon Master

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

随机推荐

  1. 25 个常用的 Linux iptables 规则【转】

    转自 25 个常用的 Linux iptables 规则 - 文章 - 伯乐在线http://blog.jobbole.com/108468/ # 1. 删除所有现有规则 iptables -F # ...

  2. pre,html转义,abbr缩写,表格table

    <pre></pre>预定义文本标签pre(保留换行和空格) <sdds>对html转义 <abbr title="sddsdsds"&g ...

  3. 八、springboot整合redis

    整合Redis 一. 注解方式实现添加缓存 1.在pom.xml加入依赖 <!-- 配置使用redis启动器 --> <dependency> <groupId>o ...

  4. java使用DOM操作XML

    XML DOM简介 XML DOM 是用于获取.更改.添加或删除 XML 元素的标准. XML 文档中的每个成分都是一个节点. DOM 是这样规定的: 整个文档是一个文档节点 每个 XML 标签是一个 ...

  5. WGS84转大地2000

    1.创建自定义地理(坐标)变换: 2.选择源坐标系和目标坐标系: 3.自定义地理转换方法,选择COORDINATE_FRAME; 4.选择投影工具: 5.在地理变换处选择刚才自定义变换.

  6. Fiddler 4 抓包(APP HTTPS )

    一.手机连接Fiddler 1.配置fiddler 1.安装fiddler,基本下一步下一步即可: 2.打开fiddler,点击顶部栏Tools——>Options 3.在HTTPS页签勾选“D ...

  7. Oracle学习笔记:decode函数

    decode函数主要作用:将查询结果翻译成其他值(即以其他形式变现出来) 使用方法: SELECT DECODE(colunm_name,值1,翻译值1,值2,翻译值2……值n,翻译值n,缺省值) F ...

  8. 34、疯狂java讲义第三版

    内容中包含 base64string 图片造成字符过多,拒绝显示

  9. wordpress后台进去空白怎么办?

    最近博客换成了用wordpress程序搭建,内容和版面也重新设计.经常使用FTP工具,更改模板或者其他程序文件.由于对wordpress不太了解,竟然出现了wordpress后台进去空白的问题,而前台 ...

  10. IDEA简单部署MVC项目

    本文章主要参考七小栈主的文章,特此说明: 前提 在配置好JDK,配置好Maven,配置链接如下:如何配置Java环境,包括JDK,Maven等 建项目 IEDA中File->New->Pr ...