Dungeon Master

Time Limit: 1000MS  Memory Limit: 10000K

Total Submissions: 40872  Accepted: 19936

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。
 //2017-02-20
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue> using namespace std; int dx[] = {, , , , -, };
int dy[] = {, , , -, , };
int dz[] = {, , , , , -}; struct node
{
int x, y, z, step;
}; int main()
{
int level, n, m;
char dun[][][];
bool vis[][][];
node tmp;
while(cin>>level>>n>>m)
{
if(level == && n == && m == )break;
queue<node> q;
memset(vis, , sizeof(vis));
for(int k = ; k < level; k++)
for(int i = ; i < n; i++)
for(int j = ; j < m; j++){
cin>>dun[i][j][k];
if(dun[i][j][k] == 'S'){
tmp.x = i;
tmp.y = j;
tmp.z = k;
tmp.step = ;
q.push(tmp);
vis[i][j][k] = ;
}
}
int x, y, z, step, nx, ny, nz;
bool ok = false;
while(!q.empty())
{
x = q.front().x;
y = q.front().y;
z = q.front().z;
step = q.front().step;
for(int i = ; i < ; i++)
{
nx = x+dx[i];
ny = y+dy[i];
nz = z+dz[i];
if(nx>=&&nx<n&&ny>=&&ny<m&&nz>=&&nz<level&&!vis[nx][ny][nz])
{
if(dun[nx][ny][nz] == '.'){
vis[nx][ny][nz] = ;
tmp.x = nx;
tmp.y = ny;
tmp.z = nz;
tmp.step = step+;
q.push(tmp);
}else if(dun[nx][ny][nz] == 'E'){
ok = true;
cout<<"Escaped in "<<step+<<" minute(s)."<<endl;
break;
}
}
}
if(ok)break;
q.pop();
}
if(!ok)cout<<"Trapped!"<<endl;
} return ;
}

POJ2251(KB1-B 三维BFS)的更多相关文章

  1. hdu 1240:Asteroids!(三维BFS搜索)

    Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

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

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

  3. POJ 2049— Finding Nemo(三维BFS)10/200

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013497151/article/details/29562915 海底总动员.... 这个题開始 ...

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

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

  5. AOJ.866 飞越原野 (三维BFS)

    AOJ.866 飞越原野 (三维BFS) 题意分析 点我挑战题目 相比于普通的BFS,要多一维来记录当前剩余的体力.而且还要额外的一层循环来处理,飞过的路程. 代码总览 #include <io ...

  6. SDUT OJ 1124 飞越原野 (三维BFS练习)

    飞跃原野 nid=24#time" title="C.C++.go.haskell.lua.pascal Time Limit5000ms Memory Limit 65536K ...

  7. Dungeon Master POJ-2251 三维BFS

    题目链接:http://poj.org/problem?id=2251 题目大意 你被困在了一个三维的迷宫,找出能通往出口的最短时间.如果走不到出口,输出被困. 思路 由于要找最短路径,其实就是BFS ...

  8. POJ2251——Dungeon Master(三维BFS)

    和迷宫问题区别不大,相比于POJ1321的棋盘问题,这里的BFS是三维的,即从4个方向变为6个方向. 用上队列的进出操作较为轻松. #include<iostream> #include& ...

  9. POJ-2251.DungeonMaster(三维BFS)

    做题时需要注意,爬楼有向上和向下爬之分... 本题大意:输入 l, r, c, 分别代表地牢的楼层数和每层地牢的长和宽,地牢由rock and point and source and key组成,你 ...

随机推荐

  1. 理解js事件冒泡事件委托事件捕获

    js事件冒泡 javascript的事件传播过程中,当事件在一个元素上出发之后,事件会逐级传播给先辈元素,直到document为止,有的浏览器可能到window为止,这就是事件冒泡现象. <di ...

  2. day 31 html(二) 和css入门

    前情提要: 本次主要是继续昨天学的简单的html 补充以及 css的简单入门 一:表单标签 >1:get请求 <!DOCTYPE html> <html lang=" ...

  3. 【xsy1230】 树(tree) 点分治+线段树

    题目大意:有一棵$n$个节点的树,点的标号为$1$到$n$.树中的边有边权.给你$m$个询问,每个询问包含三个参数$l,r,pos$,你要求出标号在$l$到$r$之间的所有点中,到节点$pos$距离最 ...

  4. [转] 使用 MVC 5 的 EF6 Code First 入门 系列

    译文:http://www.cnblogs.com/Bce-/category/573301.html 原文:http://www.asp.net/mvc/overview/getting-start ...

  5. 【优化】bigpipe技术

    一.什么是bigpipe Bigpipe是Facebook工程师提出了一种新的页面加载技术. BigPipe是一个重新设计的基础动态网页服务体系.大体思路是,分解网页成叫做Pagelets的小块,然后 ...

  6. Img与background的区别

    今天做项目中,用background显示了二维码和一些文字,但显示到页面上时,二维码和图片都变得模糊了.于是将图片调整.放大,但在放大后,作为背景图片的它则显示不全,无奈之下用了backgroung- ...

  7. 使用SharedPreference保存用户数据的步骤

    1. 声明 SharedPreferences sp; 2. 初始化 sp = this.getSharedPreferences("文件名", 0);//0代表的是私有 3. 获 ...

  8. 快速获取 json对象的长度

    JSON对象的长度,也就是k-v的个数(这里不包含隐式属性 ). 通过   Object.keys(obj) 获取到  keys组成的数组, 再获取length. var obj = { a:1, b ...

  9. java学习-GET方式抓取网页(UrlConnection和HttpClient)

    抓取网页其实就是模拟客户端(PC端,手机端...)发送请求,获得响应数据documentation,解析对应数据的过程.---自己理解,错误请告知 一般常用请求方式有GET,POST,HEAD三种 G ...

  10. koa2开发入门

    一.koa2入门 1.创建koa2工程 首先,我们创建一个目录hello-koa并作为工程目录用VS Code打开.然后,我们创建app.js,输入以下代码: // 导入koa,和koa 1.x不同, ...