poj 2251 Dungeon Master (BFS 三维)
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! 不难,二维变三维,四个方向变六个方向。但是写搜索的时候我总是好粗心导致不必要的罚时,以后切记切记。
#include <iostream>
#include <cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
using namespace std; int h,m,n,res;
char ma[][][];
bool vis[][][];
int rx[]={,,,,,-};
int ry[]={,,,-,,};
int rz[]={,-,,,,}; struct node
{
int x,y,z;
int t;
}per;
int ex,ey,ez; bool judge(node a)
{
if(a.x>=&&a.x<m&&a.y>=&&a.y<n&&a.z>=&&a.z<h)
if(!vis[a.x][a.y][a.z])
if(ma[a.x][a.y][a.z]!='#')
return true;
return false;
} bool bfs()
{
queue<node>Q;
memset(vis,false,sizeof(vis));
Q.push(per);
vis[per.x][per.y][per.z]=true;
node tmp,next;
while(!Q.empty())
{
tmp=Q.front();
Q.pop();
if(tmp.x==ex&&tmp.y==ey&&tmp.z==ez)
{
res=tmp.t;
return true;
}
for(int i=;i<;i++)
{
next.x=tmp.x+rx[i];
next.y=tmp.y+ry[i];
next.z=tmp.z+rz[i];
next.t=tmp.t+;
if(judge(next))
{
Q.push(next);
vis[next.x][next.y][next.z]=true;
}
}
}
return false;
} int main()
{
while(~scanf("%d%d%d\n",&h,&m,&n)&&(h+m+n))
{
for(int q=;q<h;q++)
for(int i=;i<m;i++)
for(int j=;j<n;j++)
{
cin>>ma[i][j][q];
if(ma[i][j][q]=='S')
{
per.x=i;per.y=j;per.z=q;
per.t=;
}
else if(ma[i][j][q]=='E')
{
ex=i;ey=j;ez=q;
}
}
//
if(bfs()) printf("Escaped in %d minute(s).\n",res);
else printf("Trapped!\n");
}
return ;
}
poj 2251 Dungeon Master (BFS 三维)的更多相关文章
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- POJ 2251 Dungeon Master【三维BFS模板】
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...
- 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最短路)
三维空间里BFS最短路 #include <iostream> #include <cstdio> #include <cstring> #include < ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- 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 ...
随机推荐
- css中伪类与伪元素的区别
一:伪类:1:定义:css伪类用于向某些选择器添加特殊效果. 伪类其实与普通的css类相类似,可以为已有的元素添加样式,但是他只有处于dom无法描述的状态下才能为文档树中的元素添加样式,所以将其称为伪 ...
- hdu 3591 多重加完全DP
题目: The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- [CodeForces - 447E] E - DZY Loves Fibonacci Numbers
E DZY Loves Fibonacci Numbers In mathematical terms, the sequence Fn of Fibonacci numbers is define ...
- EvalAI使用——类似kaggle的开源平台,不过没有kernel fork功能,比较蛋疼
官方的代码 https://github.com/Cloud-CV/EvalAI 我一直没法成功import yaml配置举办比赛(create a challenge on EvalAI 使用htt ...
- 使用virustotal VT 查询情报——感觉远远没有微步、思科好用,10万条数据查出来5万条都有postives >0的记录,尼玛!!!
1399 git clone https://github.com/VirusTotal/c-vtapi.git 1400 cd c-vtapi/ 1402 sudo apt-get install ...
- Python学习之路【第三篇】--集合
语法结构: set1.issubset(set2)判断集合set1是否为set2的子集,返回布尔值. ? 1 2 3 4 5 6 s1 = {'Java', 'PHP', 'Python', 'C++ ...
- Pl/sql 如何将oracle的表数据导出成excel文件?
oracle将表数据导出成excel文件的方法 1)在SQL窗体上,查询需要导出的数据 --查询数据条件-- ; 结果视图 2)在查询结果的空白处,右键选择Copy to Excel 3) 查看导出e ...
- sqlcipher 数据库解密
使用 sqlcipher.exe 可以在输入密码后,查看加密数据库的内容. 但是要编码查询数据库的内容,还要另寻方法.(相关的工具和库在我的百度网盘中) 使用sqlcipher windows 命令工 ...
- Linux第三周作业
1.三个法宝 ①存储程序计算机工作模型,计算机系统最最基础性的逻辑结构: ②函数调用堆栈,堆栈完成了计算机的基本功能:函数的参数传递机制和局部变量存取 : ③中断,多道程序操作系统的基点,没有中断机制 ...
- HDU 1005 Number Sequence(数论)
HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...