poj 2251 Dungeon Master
http://poj.org/problem?id=2251
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 18773 | Accepted: 7285 |
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! 分析:
典型的三维广搜。 AC代码:
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std; #define INF 0x3f3f3f3f char maz[][][];
int d[][][];
int sx,sy,sz;
int ex,ey,ez;
int dx[] = {,-,,,,};
int dy[] = {,,,-,,};
int dz[] = {,,,,,-};
int X,Y,Z;
struct P{
int x,y,z;
P(int xx,int yy,int zz) :x(xx),y(yy),z(zz) {
}
}; int bfs() {
memset(d,INF,sizeof(d));
queue<P> que;
que.push(P(sx,sy,sz));
d[sx][sy][sz] = ; while(que.size()) {
P p = que.front();que.pop(); if(p.x == ex && p.y == ey && p.z == ez) break; for(int i = ;i < ;i++) {
int nx = p.x + dx[i];
int ny = p.y + dy[i];
int nz = p.z + dz[i]; if( <= nx && nx < X && <= ny && ny < Y && <= nz && nz < Z
&& maz[nx][ny][nz] != '#' && d[nx][ny][nz] == INF) {
que.push(P(nx,ny,nz));
d[nx][ny][nz] = d[p.x][p.y][p.z] + ;
}
}
}
if(d[ex][ey][ez] == INF) return -;
return d[ex][ey][ez];
} int main() {
while(~scanf("%d %d %d",&X,&Y,&Z)) {
if(X == && Y == && Z == ) break;
for(int i = ;i < X;i++) {
for(int j = ;j < Y;j++) {
scanf("%s",maz[i][j]);
for(int k = ;k < Z;k++) {
if(maz[i][j][k] == 'S') {
sx = i;
sy = j;
sz = k;
} else if(maz[i][j][k] == 'E') {
ex = i;
ey = j;
ez = k;
}
}
}
} int res = bfs();
if(res == -) {
printf("Trapped!\n");
} else {
printf("Escaped in %d minute(s).\n",res);
}
}
return ;
}
poj 2251 Dungeon Master的更多相关文章
- 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)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- POJ 2251 Dungeon Master (非三维bfs)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55224 Accepted: 20493 ...
- POJ 2251 Dungeon Master(多层地图找最短路 经典bfs,6个方向)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48380 Accepted: 18252 ...
随机推荐
- 转:【译】CSS3:clip-path详解
我的一个学生,Heather Banks,想要实现他在Squarespace看到的一个效果: 根据她的以往经验,这个网站的HTML和CSS是完全在她的能力范围以内,于是我帮助她完成了这个效果.显示na ...
- 服务端的GET、POST请求
一.HttpClient方式,程序集 System.Net.Http.dll GET: HttpClient httpClient = new HttpClient(); string result ...
- 【水】基于ege的简单3D模拟
我们模拟从被观察物体射出光线,在眼球焦点交汇,然后打到视网膜上成像 ——足够了吧,剩下的难度应该是普及- 只是有一些常数可以自己调一下,看着顺眼就好 #include <graphics.h&g ...
- 【BZOJ3282】Tree LCT
1A爽,感觉又对指针重怀信心了呢= =,模板题,注意单点修改时splay就好,其实按吾本意是没写的也A了,不过应该加上能更好维护平衡性. ..还是得加上好= = #include <iostre ...
- JS常用属性
/*控制台输出*/ console.log("内容") /*控制台警告*/ console.warn("内容") /*错误提示*/ console.error( ...
- 细读cow.osg
细读cow.osg 转自:http://www.cnblogs.com/mumuliang/archive/2010/06/03/1873543.html 对,就是那只著名的奶牛. //Group节点 ...
- 使用BigDecimal进行精确运算以及格式化输出数字
一.引言 借用<Effactive Java>这本书中的话,float和double类型的主要设计目标是为了科学计算和工程计算.他们执行二进制浮点运算,这是为了在广域数值范围上提供 ...
- Unity3D DFGUI根据名称获取多个子控件代码
dfPanel control = gameObject.GetComponent<dfPanel>(); dfLabel avatarName = control.Find<dfL ...
- python实现之决策树
一.Predict survival on the Titanic 使用泰坦尼克号上的乘客数据,对乘客是否存活进行预测 1.观察数据集合 可能遇到的问题 训练集和测试集特征值得属性并不重合.连续属性和 ...
- mount windows-linux文件共享
. (2)在linux下访问windows共享: smbclient -L 192.168.2.12 -U admin //查看共享了那些目录,由此知道主机名为XIAOXING-PC smbcli ...