POJ2251(KB1-B 三维BFS)
Dungeon Master
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 40872 Accepted: 19936
Description
Is an escape possible? If yes, how long will it take?
Input
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
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
//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)的更多相关文章
- hdu 1240:Asteroids!(三维BFS搜索)
Asteroids! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2049— Finding Nemo(三维BFS)10/200
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013497151/article/details/29562915 海底总动员.... 这个题開始 ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- AOJ.866 飞越原野 (三维BFS)
AOJ.866 飞越原野 (三维BFS) 题意分析 点我挑战题目 相比于普通的BFS,要多一维来记录当前剩余的体力.而且还要额外的一层循环来处理,飞过的路程. 代码总览 #include <io ...
- SDUT OJ 1124 飞越原野 (三维BFS练习)
飞跃原野 nid=24#time" title="C.C++.go.haskell.lua.pascal Time Limit5000ms Memory Limit 65536K ...
- Dungeon Master POJ-2251 三维BFS
题目链接:http://poj.org/problem?id=2251 题目大意 你被困在了一个三维的迷宫,找出能通往出口的最短时间.如果走不到出口,输出被困. 思路 由于要找最短路径,其实就是BFS ...
- POJ2251——Dungeon Master(三维BFS)
和迷宫问题区别不大,相比于POJ1321的棋盘问题,这里的BFS是三维的,即从4个方向变为6个方向. 用上队列的进出操作较为轻松. #include<iostream> #include& ...
- POJ-2251.DungeonMaster(三维BFS)
做题时需要注意,爬楼有向上和向下爬之分... 本题大意:输入 l, r, c, 分别代表地牢的楼层数和每层地牢的长和宽,地牢由rock and point and source and key组成,你 ...
随机推荐
- Flask的WTforms
一.简单介绍 WTForms是一个支持多个web框架的form组件,主要用于对用户请求数据进行验证. 类似于Django中的modelform 安装: pip3 install wtforms 二.简 ...
- hdoj1180 诡异的楼梯(bfs+奇偶判断)
手癌!日常手癌!被自己气死! #include<iostream> #include<cstring> #include<queue> #include<al ...
- css单行文本及多行文本溢出显示省略号
关于文本溢出的相关属性: 1. text-overflow: clip|ellipsis|string; 该属性规定当文本溢出包含元素时发生的事情. clip : 修剪文本. ellipsis : ...
- Redis数据类型之SDS简单动态字符串
一,简单的动态字符串 1,Redis自己构建了一种名为简单动态字符串的抽象类型,并将SDS用作Redis的默认字符串表示, 2,在redis的数据库里面,包含字符串值的键值对在底层都是由SDS实现的 ...
- (转)使用 DB2 HADR 选择用于灾难恢复的 SUPERASYNC 模式
使用 DB2 HADR 选择用于灾难恢复的 SUPERASYNC 模式 Vishnu G 和 Hemant Singh2013 年 6 月 25 日发布 WeiboGoogle+用电子邮件发送本页面 ...
- gitHub-高仿58同城加载动画
导入方式: /build.gradle repositories { maven { url "https://jitpack.io" } } /app/build.gradle ...
- 安装以及构建SSIS
SSIS使用教程可以参照微软官网实例:https://msdn.microsoft.com/zh-cn/library/ms169917(v=sql.105).aspx 1.安装visual stud ...
- Chapter 3 Phenomenon——3
It took every ounce of my concentration to make it down the icy brick driveway alive. 我用所有我的注意力去确定车道 ...
- 如何在python3环境下的Django中使用MySQL数据库
我们在使用Django过程中,连接MySQL数据库时,对Python不同的版本对应的库也不一样,用惯了Python2的人在使用Python3时经常会遇到下面的错误: Error loading MyS ...
- boost bind使用指南
bind - boost 头文件: boost/bind.hpp bind 是一组重载的函数模板.用来向一个函数(或函数对象)绑定某些参数. bind的返回值是一个函数对象. 它的源文件太长了. 看不 ...