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 ...
随机推荐
- Word2007怎样从随意页開始设置页码 word07页码设置毕业论文
Word2007怎样从随意页開始设置页码 word07页码设置毕业论文 页開始设置页码. 一.插入页码 插入→页眉和页脚→页码→页面底端→普通数字3 说明:被→分隔的内容分别为选项卡,模块,命令but ...
- hive 配置文件以及join中null值的处理
一.Hive的參数设置 1. 三种设定方式:配置文件 · 用户自己定义配置文件:$HIVE_CONF_DIR/hive-site.xml · 默认配置文件:$HIVE_CONF_DIR/hi ...
- 浙江大学PAT上机题解析之1014. 福尔摩斯的约会 (20)
1014. 福尔摩斯的约会 (20) 时间限制 50 ms 内存限制 32000 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Y ...
- dump_stack的简单使用 +CALL TREE
http://blog.chinaunix.net/uid-26403844-id-3361770.html http://blog.csdn.net/zifeng274059226/article/ ...
- IOS-CGAffineTransformMake 矩阵变换 的运算原理
1.矩阵的基本知识: struct CGAffineTransform { CGFloat a, b, c, d; CGFloat tx, ty; }; CGAffineTransform C ...
- RSA 加解密 签名 示例
import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.FileOutputStrea ...
- 一道阿里面试题(js)
写一个求和的函数sum,达到下面的效果 // Should equal 15 sum(1, 2, 3, 4, 5); //Should equal 0 sum(5, 'abc', -5); //Sho ...
- Html网页生成Pdf
在http://code.google.com/p/wkhtmltopdf/downloads/list下载安装程序. 1.添加引用 using System.Diagnostics; 添加引用 2. ...
- MySQL性能状态查看方式
1. QPS(每秒Query量) QPS = Questions(or Queries) / seconds mysql > show global status like 'Question% ...
- 线程同步(AutoResetEvent与ManualResetEvent)
前言 在我们编写多线程程序时,会遇到这样一个问题:在一个线程处理的过程中,需要等待另一个线程处理的结果才能继续往下执行.比如:有两个线程,一个用来接收Socket数据,另一个用来处理Socket数据, ...