Dungeon Master(poj 2251)
Description
Is an escape possible? If yes, how long will it take?
Input
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!
题意:3维迷宫!“.”是路;“#”是墙,“E"进“S”出
这题的题目略有小坑;
注意几个地方:1.数组开到105以上;2.队列清空;
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
int s[][][];
int vis[][][];
int r[]= {-,,,,,};
int c[]= {,,-,,,};
int h[]= {,,,,,-};
int ei,ej,ek;
struct node
{
int a,b,c;
int step;
};
node p,q;
void getit(int I,int J,int K)//输入并处理
{
char ch;
int i,j,k;
for(k=; k<K; k++)
{
for(i=; i<I; i++)
{
for(j=; j<J; j++)
{
scanf("%c",&ch);
if(ch=='.')
s[i][j][k]=-;
else if(ch=='E')
{
ei=i;
ej=j;
ek=k;
}
else if(ch=='S')
s[i][j][k]=;
}
getchar();
}
getchar();
}
}
void bfs(int ai,int aj, int ak,int step)//简单BFS
{
queue<node>que;
vis[ai][aj][ak]=;
int t;
p.a=ai;
p.b=aj;
p.c=ak;
p.step=step;
que.push(p);
while(!que.empty())
{
p=que.front();
que.pop();
for(t=; t<; t++)
{
q.a=p.a+r[t];
q.b=p.b+c[t];
q.c=p.c+h[t];
q.step=p.step+;
if(s[q.a][q.b][q.c]&&!vis[q.a][q.b][q.c])
{
if(s[q.a][q.b][q.c]==)
{
printf("Escaped in %d minute(s).\n",q.step);
return ;
}
que.push(q);
vis[q.a][q.b][q.c]=;
}
}
}
printf("Trapped!\n");
}
int main()
{ int I,J,K;
while(scanf("%d %d %d",&K,&I,&J)&&(I||J||K))
{
getchar();
memset(s,,sizeof(s));//置空
memset(vis,,sizeof(vis));
getit(I+,J+,K+);
bfs(ei,ej,ek,);
}
return ;
}
Dungeon Master(poj 2251)的更多相关文章
- Dungeon Master (POJ - 2251)(BFS)
转载请注明出处: 作者:Mercury_Lc 地址:https://blog.csdn.net/Mercury_Lc/article/details/82693907 题目链接 题解:三维的bfs,一 ...
- 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地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- 【POJ - 2251】Dungeon Master (bfs+优先队列)
Dungeon Master Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...
- 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)
BUPT2017 wintertraining(16) #5 B POJ - 2251 题意 3维的地图,求从S到E的最短路径长度 题解 bfs 代码 #include <cstdio> ...
- POJ 2251 Dungeon Master(多层地图找最短路 经典bfs,6个方向)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48380 Accepted: 18252 ...
随机推荐
- [CodeForce]356D Bags and Coins
已知有n个包,和总共s个钱币. n,s<=70000. 每个包可以装钱币,还可以套别的包.每个包中的钱数等于 所有套的包的钱数 加上 自己装的钱. 所有的钱都在包内. 问给定每个包中的钱数,输出 ...
- 了解ANSI编码
ANSI:American National Standards Institute:美国国家标准学会 ANSI编码:为使计算机支持更多语言,不同国家和地区分别制定了符合自身的外文字符延伸编码方式(如 ...
- block没那么难(二):block和变量的内存管理
本系列博文总结自<Pro Multithreading and Memory Management for iOS and OS X with ARC> 了解了 block的实现,我们接着 ...
- Oracle修改被占用的临时表结构
这两天在修改临时表的类型时,提示”attempt to create,alter or drop an index on temporary table already in use“的错误,由于临时 ...
- 10.4 noip模拟试题
题目名称 PA 青春 三部曲 名称 huakai taritari truetears 输入 huakai.in taritari.in truetears.in 输出 huakai.out tari ...
- 用Javascript进行HTML转义(分享)
众所周知页面上的字符内容通常都需要进行HTML转义才能正确显示,尤其对于Input,Textarea提交的内容,更是要进行转义以防止javascript注入攻击. 通常的HTML转义主要是针对 ...
- Java-Hibernate官方英文文档地址
Hibernate官方英文文档地址 http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/
- Sql2008中使用DataTable作为存储过程的参数
使用DataTable作为存储过程的参数 最近工作中写了几个存储过 程,需要向存储过程中传递字符串,因为SQL Server 2000中没有内置类似于 split 的函数,只好自己处理,将前台数据 ...
- nodejs开发环境sublime配置
前端时间使用webstorm搭建一个node.js的学习环境,感觉非常强大.不过由于其加载的速度,每次让都让我抓狂.后来我找到了一个sublime.虽说3.0以上是收费的,2.0暂时免费.官方的不对s ...
- 函数对象的prototype总结
通过看 http://www.cnblogs.com/mindsbook/archive/2009/09/19/javascriptYouMustKnowPrototype.html 该文章和对代码的 ...