BFS POJ2251 Dungeon Master
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
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水题,套模板按6个方向拓展就行了。
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <string.h>
using namespace std;
int to[][] = {{,,},{,,-},{,,},{,-,},{,,},{-,,}};
char s[][][];
int maps[][][];
int x1,y1,z1;
int x2,y2,z2;
int L,R,C;
struct data
{
int x;
int y;
int z;
int step;
};
int check(int x,int y,int z)
{
if(x< || y< || z< || x>=L || y>=R || z>=C)
return ;
else if(s[x][y][z] == '#')
return ;
else if(maps[x][y][z])
return ;
return ;
}
int bfs()
{
queue<data> q;
data now,nex;
now.x=x1;
now.y=y1;
now.z=z1;
now.step=;
maps[x1][y1][z1]=;
q.push(now);
while(!q.empty())
{
now=q.front();
q.pop();
if(now.x==x2&&now.y==y2&&now.z==z2)
{
return now.step;
}
for(int i=;i<;i++)
{ nex=now;
nex.x=now.x+to[i][];
nex.y=now.y+to[i][];
nex.z=now.z+to[i][];
if(check(nex.x,nex.y,nex.z))
{
continue;
}
maps[nex.x][nex.y][nex.z]=;
nex.step=now.step+;
q.push(nex);
}
}
return ;
}
int main()
{
while(scanf("%d%d%d",&L,&R,&C),L+R+C)
{
cin>>R>>C;
int i,j,k;
for(i=;i<L;i++) //
{
for(j=;j<R;j++)
{
scanf("%s",s[i][j]);
for(k=;k<C;k++)
{
if(s[i][j][k]=='S')
{
x1=i;
y1=j;
z1=k;
}
else if(s[i][j][k]=='E')
{
x2=i;
y2=j;
z2=k;
}
}
}
}
memset(maps,,sizeof(maps));
int ans;
ans=bfs();
if(ans)
{printf("Escaped in %d minute(s).\n",ans);}
else
{
printf("Trapped!\n");
}
}
return ;
}
BFS POJ2251 Dungeon Master的更多相关文章
- POJ2251 Dungeon Master —— BFS
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ-2251 Dungeon Master (BFS模板题)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- POJ2251 Dungeon Master(bfs)
题目链接. 题目大意: 三维迷宫,搜索从s到e的最小步骤数. 分析: #include <iostream> #include <cstdio> #include <cs ...
- POJ2251——Dungeon Master(三维BFS)
和迷宫问题区别不大,相比于POJ1321的棋盘问题,这里的BFS是三维的,即从4个方向变为6个方向. 用上队列的进出操作较为轻松. #include<iostream> #include& ...
- bfs—Dungeon Master—poj2251
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32228 Accepted: 12378 ...
- 【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(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master (非三维bfs)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55224 Accepted: 20493 ...
随机推荐
- BZOJ 2741: 【FOTILE模拟赛】L [分块 可持久化Trie]
题意: 区间内最大连续异或和 5点调试到现在....人生无望 但总算A掉了 一开始想错可持久化trie的作用了...可持久化trie可以求一个数与一个数集(区间中的一个数)的最大异或和 做法比较明显, ...
- BZOJ 2342: [Shoi2011]双倍回文 [Manacher + set]
题意: 求最长子串使得它有四个相同的回文串SSSS相连组成 枚举中间x 找右边的中间y满足 y-r[y]<=x y<=x+r[x]/2 用个set维护 注意中间只能是# #include ...
- Language Modeling with Gated Convolutional Networks
语言模型 所谓的语言模型,即是指在得知前面的若干个单词的时候,下一个位置上出现的某个单词的概率. 最朴素的方法是N-gram语言模型,即当前位置只和前面N个位置的单词相关.如此,问题便是,N小了,语言 ...
- LeetCode - 307. Range Sum Query - Mutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- WEB-INF目录下文件复制的几种方式
2018年1月31日 10:42:55 工作完写点博客记录下. 需求:从web-inf下拷贝文件到指定目录. 目录结构 直接贴代码 第一种方式,字节流读取 try { int index = 0; S ...
- CentOS6.8配置GO语言开发环境
Go语言是谷歌2009发布的第二款开源编程语言,Go语言专门针对多处理器系统应用程序的编程进行了优化,使用Go编译的程序可以媲美C或C++代码的速度,而且更加安全.支持并行进程. 鉴于原来越多的开源项 ...
- [bzoj3998][TJOI2015]弦论-后缀自动机
Brief Description 给定一个字符串, 您需要求出他的严格k小子串或非严格k小子串. Algorithm Design 考察使用后缀自动机. 首先原串建SAM, 然后如果考察每个状态代表 ...
- vim插件安装总结
vim插件安装总结 vim 插件 vundle 插件对于vim来说是一个杀手级别的神器助手,能自动补全,语法高亮,文件搜索等等,有效地提升了编程效率.下面就个人的一些安装和使用进行一个总结. 自动管理 ...
- Linux CentOs集群LVS+Keepalived负载均衡的实现
准备工作 环境:Win10下Centos6.4虚拟机. 负载均衡:两台(一主一备) LVS + Keepalived. HTTP服务器:3台. 给每台服务器配置IP 1.VIP(virtual ip ...
- 如何使用 VS2015 进行远程调试?
VisualStudio\Microsoft Visual Studio 14.0\Common7\IDE\Remote Debugger 直接复制 Remote Debugger 文件,里面包含了 ...