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. 关于app的cpu占用率想到的几个问题

    1.top 命令获取的cpu是手机瞬间的cpu 2.dumpsys获取的是一段时间cpu的平均值?那么这段时间是指哪段,从哪开始到什么时候结束? 3.如果想测试app某操作下的cpu占用情况时候.应该 ...

  2. Docker基础速成(一)

    Docker基础速成(一) 给亲爱的写的docker基础速成,按照步骤操作,实践出真知,希望有提纲挈领之功效 1.docker简介 Docker 轻量级容器,如图,类似于一个个集装箱,把复杂或者零散的 ...

  3. shell函数-页面跳转练习->

    实现思维导图-> 实现思路-> 分析:1:先把三个页面的流程作为函数先写下来,定义在脚本的开头,方便下面的调用.2:先从一个流 程开始做,其他的流程类似,比如nginx3:整体实现思路是 ...

  4. MongoDB安全:所有操作(Privilege Actions)

    本文展示了两张思维导图,分别是MongoDB 3.6.4.0的所有权限操作,未做深入研究,仅仅是列出来. 3.6总共9类105个操作,4.0版本比3.6多了两类操作,同时增加了3个操作,共11类108 ...

  5. python基础学习之路No.2 数据类型

    python中常见的数据类型有:整数.浮点数.字符串.列表.元组.字典 python相较其他语言,可以省略了声明,可以直接定义赋值使用. 例如: a=12 就相当于 其他语言中的  int a=12  ...

  6. OpenCV与Python之图像的读入与显示以及利用Numpy的图像转换

    1:读入图像,显示图像与保存图像 代码: import cv2 img=cv2.imread('lena.jpg',cv2.IMREAD_COLOR) cv2.namedWindow('lena',c ...

  7. SP_attach_db 添加数据库文件

    SP_attach_db   用法如下:       EXEC   SP_attach_db   @dbname   =   N'目标数据库名',           //这是你要引入后的数据库名. ...

  8. PHP的XML Parser(转)

    PHP处理XML文件 一.读取,更新(创建或者操作)一个XML文档,需要XML解析器 .有两种XML parsers: 1. Tree-based parser:将XML文档转化为DOM Tree结构 ...

  9. 安装部署Apache Hadoop (本地模式和伪分布式)

    本节内容: Hadoop版本 安装部署Hadoop 一.Hadoop版本 1. Hadoop版本种类 目前Hadoop发行版非常多,有华为发行版.Intel发行版.Cloudera发行版(CDH)等, ...

  10. contabs.js 的使用

    1. 先下载两个文件 https://files.cnblogs.com/files/xiaojf/style.css https://files.cnblogs.com/files/xiaojf/c ...