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. python使用twisted搭建的一个socket服务

    服务端 # -*- coding: utf-8 -*- # @Time : 2018/9/19 21:41 # @Author : cxa # @File : tsTservTW.py # @Soft ...

  2. Spark RDD 窄依赖研究

    1.. 简介 spark从RDD依赖上来说分为窄依赖和宽依赖. 其中可以这样区分是哪种依赖:当父RDD的一个partition被子RDD的多个partitions引用到的时候则说明是宽依赖,否则为窄依 ...

  3. 经典面试题:js继承方式上

    js不是传统的面向对象语言,那么他是怎么实现继承的呢?由于js是基于原型链实现的面向对象,所以js主要通过原型链查找来实现继承,主要有两大类实现方式,分为基于构造函数的继承,以及非构造函数的继承. 由 ...

  4. Bootstrap FileInput 多图上传插件 文档属性说明

    Bootstrap FileInput 多图上传插件   原文链接:http://blog.csdn.net/misterwho/article/details/72886248?utm_source ...

  5. OKR.2019

    转眼又一年过去了,回顾审视一年的得失,规划下一年的奋斗目标.Review And Planning,让全新的2019迎来全新的自己. O1 学习软件开发技术知识 KR1.1 阅读<CLR via ...

  6. Effective STL 学习笔记 Item 30: 保证目标区间足够大

    Effective STL 学习笔记 Item 30: 保证目标区间足够大 */--> div.org-src-container { font-size: 85%; font-family: ...

  7. 【Sequel Pro】下载查询结果乱码问题处理方式

    1.下载查询结果已CSV格式保存 2.出现乱码问题样式如下截图: 3. 右键下载的CSV文件,选择用文本编辑打开 4.全选打开的页面内容,重新新建“文本编辑”并进行“储存” 5.打开 1.CSV,则看 ...

  8. 【51nod】1531 树上的博弈

    题解 我们发现每次决策的时候,我们可以判断某个点的决策,至少小于等于几个点或者至少大于等于几个点 我们求最大值 dp[u][1 / 0] dp[u][1]表示u这个点先手,至少大于等于几个点 dp[u ...

  9. Django实战(17):ajax !

    现在让我们来通过ajax请求后台服务.当然首选要实现后台服务.关于“加入购物车”,我们需要的服务是这样定义的: url:    http://localhost:8000/depotapp/API/c ...

  10. ffmpeg 添加filter步骤

    a). 自己写一个XXX.c文件,比如vf_transform.c,放在libavfilter目录下.代码可以参考其他filter: b) 在libavfilter/allfilters.c添加一行: ...