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

    1: 构造函数的伪装.(JS继承的时候出现 通过call函数改变this指向的对象) 2: 原型链.(JS继承的时候出现) 3:宿主对象:(有浏览器提供的对象.DOM, BOM  - Document ...

  2. C/C++ 语言 Hello world

    #include <stdio.h> void main() { int x,i; ; scanf("%d",&x); if(x>y) printf(&q ...

  3. ng的点滴记录

    1,directive http://damoqiongqiu.iteye.com/blog/1917971/ 2,constructor  https://segmentfault.com/q/10 ...

  4. 常见无线组网分析(NB-IOT组网和Mesh组网)

      NB-IOT LoRa Zigbee WIFI 蓝牙 组网方式 基于现有蜂窝组网 基于LoRa网关 基于Zigbee网关 基于无线路由器 居于蓝牙Mesh的网关 网络部署方式 节点 节点 + 网关 ...

  5. 彻底弄懂css3的flex弹性盒模型

    由于在日常工作中使用css或者bootstrap的栅格系统已经能很好的满足业务需求,所以一直以来对css3的弹性布局不是很感冒. 近日有幸在一篇文章中领略了flex的魅力--简洁优雅.随试之. /*容 ...

  6. centos7 防火墙与端口设置、linux端口范围

    防火墙 启动防火墙: systemctl start firewalld 查看防火墙状态: systemctl status firewalld 关闭防火墙: systemctl stop firew ...

  7. if嵌套语句 shell脚本实例 测试是否闰年

    在 if 语句里面,你可以使用另外一个 if 语句.只要你能逻辑管理 你就可以使用多层嵌套. 以下是一个测试闰年的例子: #!/bin/bash # This script will test if ...

  8. 【bat/cmd】脚本开发

    0. 开篇 bat/cmd 均是window操作系统下,两者都是通过文本方式编辑,创建以及查看.均是命令的集合.bat与cmd有什么区别呢 ? 1) cmd文件允许使用的命令比bat多,但是只有在wi ...

  9. .gitignore释疑

    自己总结: *.a--匹配任意路径下的.a文件 a/--匹配任意路径下的a文件夹 a/*--匹配根目录下的文件夹a下的任意文件(等同于 /a/* 或 /a/)  ----一般情况下不会有这种写法 /a ...

  10. LINUX 下 NMAP 内网扫描

    #1.扫描内网存活主机 nmap -sP 10.2.24.* |grep for > tmp #2.扫描主机端口 nmap -A -T4 192.168.1.2 #3.扫描主机的所有端口 nma ...