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 ...
随机推荐
- mysqldump备份数据库时出现when using LOCK TABLES
用mysqldump备份数据库时,如果出现when using LOCK TABLES,解决办法是加上 --skip-lock-tables 例如: 用mysqldump备份数据库时出现 29: Fi ...
- Java设计模式05:常用设计模式之原型模式(创建型模式)
1. Java之原型模式(Prototype Pattern) 原型模式属于对象的创建模式.通过给出一个原型对象来指明所有创建的对象的类型,然后用复制这个原型对象的办法创建出更多同类型的对象. ...
- 第一篇:python基础
python基础 python基础 本节内容 python起源 python的发展史 为什么选择python3 第一个python程序 变量定义 表达式和运算符 用户输入 流程控制 判断 流程控制 ...
- 如果 @s int 把它转成字符,可以这样 cast(@s as varchar)
如果 @s int 把它转成字符,可以这样 cast(@s as varchar)
- WinForm中的事件触发机制学习
在一个Form窗体中拖个按钮,双击后系统自动生成代码: private void button1_Click(object sender, EventArgs e) { } 同时在窗体的Initial ...
- 【算法】数组与矩阵问题——找到无序数组中最小的k个数
/** * 找到无序数组中最小的k个数 时间复杂度O(Nlogk) * 过程: * 1.一直维护一个有k个数的大根堆,这个堆代表目前选出来的k个最小的数 * 在堆里的k个元素中堆顶的元素是最小的k个数 ...
- 英语学习[ZZ]
本文作者三年间从四级勉强及格到高级口译笔试210,口试232.找工作面试时给其口试的老外考官听了一分钟就说你的英语不用考了.虽不敢说方法一定是最好的,但从现在开始随便谁不要再去找学习资料,每天花两个钟 ...
- error C2220: warning treated as error - no 'object' file generated解决方法
error C2220: warning treated as error - no 'object' file generated 警讯视为错误 - 生成的对象文件 / WX告诉编译器将所有警告视为 ...
- SGU 163.Wise King
一道题目长的水题.... 总结就一句话,给出n个(-3~3)的数,一个数m,取任意个数是使这些数的m次幂之和最大. code #include <iostream> #include &l ...
- IE6双倍margin间距解决方案
问题:在IE6下如果某个标签使用了float属性,同时设置了其外补丁“margin:10px 0 0 10px”可以看出,上边距和左边距同样为10px,但第一个对象距左边有20px. 解决 ...