POJ-2251 Dungeon Master (BFS模板题)
Is an escape possible? If yes, how long will it take?
Input
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
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! 题目分析:BFS模板题。
# include<iostream>
# include<cstdio>
# include<algorithm>
# include<cstring>
# include<queue>
using namespace std;
struct node
{
int x,y,z,t;
node(int a,int b,int c,int d):x(a),y(b),z(c),t(d){}
bool operator < (const node &a) const {
return t>a.t;
}
};
char p[][][],vis[][][];
int l,r,c;
int d[][]={{,,},{,,-},{,,},{-,,},{,,},{,-,}};
void bfs(int sx,int sy,int sz)
{
priority_queue<node>q;
memset(vis,,sizeof(vis));
vis[sx][sy][sz]='';
q.push(node(sx,sy,sz,));
while(!q.empty())
{
node u=q.top();
q.pop();
if(p[u.x][u.y][u.z]=='E'){
printf("Escaped in %d minute(s).\n",u.t);
return ;
}
for(int i=;i<;++i){
int nx=u.x+d[i][],ny=u.y+d[i][],nz=u.z+d[i][];
if(nx>=&&nx<r&&ny>=&&ny<c&&nz>=&&nz<l&&!vis[nx][ny][nz]&&p[nx][ny][nz]!='#'){
vis[nx][ny][nz]='';
q.push(node(nx,ny,nz,u.t+));
}
}
}
printf("Trapped!\n");
}
int main()
{
while(scanf("%d%d%d",&l,&r,&c),l+r+c)
{
int sx,sy,sz;
for(int k=;k<l;++k){
for(int i=;i<r;++i){
for(int j=;j<c;++j){
cin>>p[i][j][k];
if(p[i][j][k]=='S')
sx=i,sy=j,sz=k;
}
}
}
bfs(sx,sy,sz);
}
return ;
}
代码如下:
POJ-2251 Dungeon Master (BFS模板题)的更多相关文章
- poj 2251 Dungeon Master( bfs )
题目:http://poj.org/problem?id=2251 简单三维 bfs不解释, 1A, 上代码 #include <iostream> #include<cst ...
- POJ 2251 Dungeon Master bfs 难度:0
http://poj.org/problem?id=2251 bfs,把两维换成三维,但是30*30*30=9e3的空间时间复杂度仍然足以承受 #include <cstdio> #inc ...
- 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 ...
- POJ 2251 Dungeon Master (BFS最短路)
三维空间里BFS最短路 #include <iostream> #include <cstdio> #include <cstring> #include < ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
- POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)
POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
随机推荐
- MySQL笔记(二)数据库对象的创建和管理
学校用 sqlserver ,记录数据移植到 mysql 过程中的一些问题(对应数据类型,主键外键等). 索引: 查看数据的物理路径 查看表相关的信息(SHOW CREATE TABLE.DESC) ...
- mysql5.6升级及mysql无密码登录
mysql5.6升级 mysql5.6的升级可以分为以下几个步骤: 安全关闭正在运行的MySQL实例 把/usr/local/mysql 的连接由MySQL5.6更改为MySQL5.7 启动MySQL ...
- 03: 自定义异步非阻塞tornado框架
目录:Tornado其他篇 01: tornado基础篇 02: tornado进阶篇 03: 自定义异步非阻塞tornado框架 04: 打开tornado源码剖析处理过程 目录: 1.1 源码 1 ...
- mysql免安装版本(用批处理安装和启动)
参考文章: http://www.cnblogs.com/niuniutry/p/3555778.html http://wenku.baidu.com/link?url=WI9Cyl5AMHOlps ...
- 使用PopupWindow弹窗提醒
一.新建view.xml 注意里面的控件要一个一个的定义离上一个控件的距离,即margin_top,不然最后的效果是紧缩的 二.在java中定义两个变量 1.View view=null: 2.pop ...
- Python3基础 tuple 通过拆分元组向元组中加入新的元素
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 【LTE基础知识】SGLTE, SVLTE, CSFB, VoLTE【转】
本文转载自:https://blog.csdn.net/henryghx/article/details/18416405 4G网络下实现语音通话功能的技术共有三种——VoLTE.SGLTE(GSM ...
- Autotools使用流程【转】
本文转载自:http://blog.csdn.net/scucj/article/details/6079052 手工写Makefile是一件很有趣的事情,对于比较大型的项目,如果有工具可以代劳,自然 ...
- 移植openssh到arm linux
一.在移植之前需要准备做一些前期准备: 1.移植zlib库 1.1获取zlib源码 1.2解压 tar xvf zlib-1.2.11.tar.xz 1.3交叉编译 1.3.1 指定交叉编译器 exp ...
- 【TCP/IP详解 卷一:协议】第十二章 广播与多播 ping实验
我手机连接到wifi上所分配到的IP地址:192.168.1.116 子网掩码:255.255.255.0 路由器:192.168.1.1 ping 192.168.1.116 (ping 一台主机的 ...