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组成,你 ...
随机推荐
- 五,mysql优化——sql语句优化小技巧
1,大批量插入数据 (1)对于MyISAM: alter table table_name disable keys; loading data; alter table table_name ena ...
- Android安全防护防护———Android 端常见的安全问题
Android安全防护防护——加密算法:传送门https://www.cnblogs.com/huangjialin/p/9694488.html 组件安全 activity劫持 简单来说就是正常的a ...
- 关于使用Iscroll.js异步加载数据后不能滑动到最底端的问题解决方案
关于使用Iscroll.js异步加载数据后不能滑动到最底端,拉到最下边又弹回去的问题困扰了我老半天,相信很多朋友都遇到了.我刚好不小心解决了,和大家分享一下.由于各种忙,下边就直接上代码吧. (前提是 ...
- Redis 的 Sentinel
Redis 的 Sentinel 系统用于管理多个 Redis 服务器(instance), 该系统执行以下三个任务: 监控(Monitoring): Sentinel 会不断地检查你的主服务器和从服 ...
- LINUX中如何查看某个端口是否被占用
之前查询端口是否被占用一直搞不明白,问了好多人,终于搞懂了,现在总结下: 1.netstat -anp |grep 端口号 如下,我以3306为例,netstat -anp |grep ...
- python相见恨晚的库
1)基本工具: virtualenv(虚拟环境)pip.setuptools (e.g. easy_install,这些东西肯定要呢)ipython(用了以后,就不再想用普通的python shell ...
- [Noi2014]购票 斜率优化DP+可持久化凸包
貌似网上大部分题解都是CDQ分治+点分治然后再斜率优化DP,我貌似并没有用这个方法. 这一题跟这题有点像,只不过多了一个l的限制 如果说直接跑斜率优化DP,存储整个序列的话,显然是不行的,如图所示(图 ...
- js delete删除对象属性,delete删除不了变量及原型链中的变量
js delete删除对象属性,delete删除不了变量及原型链中的变量 一.delete删除对象属性 function fun(){ this.name = 'gg'; } var obj = ne ...
- node开发环境配置
node开发环境配置 用处 NodeJS——后台 JavaScript-前台 后台其他语言 1.PHP 2.Java 3.Pythonnode优势 1.性能高 nodejs php 86 1s 1分半 ...
- Oracle 数据库维护管理之--dbms_lock
1.查询相关的v$视图,但是提示表或视图不存在解决办法 原因是使用的用户没有相关的查询权限导致 解决办法: grant select any dictionary to 用户; --这 ...