POJ 2251-Dungeon Master (三维空间求最短路径)
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! 开三维数组用BFS求。
#include<cstdio>
#include<queue>
using namespace std;
int dx[]={-,,,,,};
int dy[]={,,-,,,};
int dz[]={,,,,,-};
char str[][][];
int l,r,c,i,j,k,ans,bx,bz,by;
struct stu
{
int x,y,z,step;
};
bool f(stu st)
{
if(st.x< || st.z< || st.y< || st.x>=r || st.y>=c || st.z>=l || str[st.z][st.x][st.y] =='#')
{
return false;
}
return true;
}
int bfs(int bz,int bx,int by)
{
str[bz][bx][by]='#';
int nx,ny,time,zz,xx,yy;
queue<stu> que;
stu st,next;
st.x=bx;
st.y=by;
st.z=bz;
st.step=;
que.push(st); while(!que.empty())
{ st=que.front();
que.pop(); xx=st.x;
yy=st.y;
zz=st.z;
time=st.step;
for(i = ;i < ; i++)
{
st.x=xx+dx[i];
st.y=yy+dy[i];
st.z=zz+dz[i];
if(!f(st))
{
continue;
}
if(str[st.z][st.x][st.y] == 'E')
{
return time+;
} st.step=time+;
que.push(st);
str[st.z][st.x][st.y]='#';
}
}
return ;
}
int main()
{
while(scanf("%d %d %d",&l,&r,&c)&&l&&r&&c)
{
for(i = ; i < l ; i++)
{
for(j = ; j < r ;j++)
{
scanf("%s",str[i][j]);
for(k = ; k < c ; k++)
{
if(str[i][j][k] == 'S')
{
bz=i;
bx=j;
by=k;
}
}
}
}
ans=bfs(bz,bx,by);
if(ans)
printf("Escaped in %d minute(s).\n",ans);
else
printf("Trapped!\n"); }
}
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 (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- 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 ...
- 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
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- POJ 2251 Dungeon Master(三维空间bfs)
题意:三维空间求最短路,可前后左右上下移动. 分析:开三维数组即可. #include<cstdio> #include<cstring> #include<queue& ...
- 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 You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is ...
随机推荐
- iOS 上传的图片在HTML上显示时,图片方向信息(EXIF Orientation)异常
将iPhone 6s拍摄的照片上传到服务器之后, 在Web网页上看到图片被逆时针旋转了90度, 这让我很惆怅呐! 出现这个问题其实是因为上传的图片为.jpg格式,.jpg文件含有EXIF信息, 其中E ...
- Codeforces Round #395 (Div. 2) D
Description One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On t ...
- Folding UVA - 1630
题目 ans[i][j]表示由原串第i个字符到第j个字符组成的子串的最短折叠长度如果从i到j本身可以折叠,长度就是本身长度或折叠后的长度的最小值***此处参考:http://blog.csdn.net ...
- Mysql的外键
概念:如果一个实体A的某一字段,刚好指向或引用另一个实体B的主键,那么实体A的这个字段就叫作外键,所以简单来说,外键就是外面的主键,就是其他表的主键. 例: 以上的学生表的班级字段,就是一个外键! 其 ...
- selenium处理的操作
- 纯js手动分页
昨天让做个页面,后台提供所有数据,没有做好分页,需要前端js手动分页. 我参考了 http://www.cnblogs.com/jiechn/p/4095029.html 做了些许改动让分页效果更加完 ...
- D. The Door Problem 带权并查集
http://codeforces.com/contest/776/problem/D 注意到每扇门都有两个东西和它连接着,那么,如果第i扇门的状态是1,也就是已经打开了,那么连接它的两个按钮的状态应 ...
- new几种用法
在 C# 中,new 关键字可用作运算符.修饰符或约束. new 运算符 用于创建对象和调用构造函数. new 修饰符 用于向基类成员隐藏继承成员. new 约束 用于在泛型声明中约束可能用作类型参数 ...
- AJPFX总结面向对象(this和super的区别和应用)
面向对象(this和super的区别和应用)(掌握)* A:this和super都代表什么 * this:代表当前对象的引用,谁来调用我,我就代表谁 * super:代表当 ...
- Eigen3的安装