POJ 2251 三维BFS(基础题)
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!
Source
#include "cstdio"
#include "stdlib.h"
#include "iostream"
#include "algorithm"
#include "string"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#define mj
#define db double
#define ll long long
using namespace std;
const int N=1e8+;
const int mod=1e9+;
const ll inf=1e16+;
bool v[][][];
int dx[]={,,,,-,},dy[]={,,,,,-},dz[]={-,,,,,};
int a,b,c;
char s[][][];
int d[][][];
typedef struct P{
int x,y,z;
P(int c,int d,int e){
z=c,x=d,y=e;
}
};
void bfs(P t){
queue<P> q;
for(int i=;i<;i++)
for(int j=;j<;j++)
for(int k=;k<;k++)
d[i][j][k]=N;
q.push(t);
memset(v,, sizeof(v));
d[t.z][t.x][t.y]=;
v[t.z][t.x][t.y]=;
while(q.size()){
P p=q.front();
q.pop();
if(s[p.z][p.x][p.y]=='E'){
printf("Escaped in %d minute(s).\n",d[p.z][p.x][p.y]);
return;
} for(int i=;i<;i++){
int nx=p.x+dx[i],ny=p.y+dy[i],nz=p.z+dz[i];
if(<=nx&&nx<b&&<=ny&&ny<c&&<=nz&&nz<a&&s[nz][nx][ny]!='#'&&!v[nz][nx][ny]){
d[nz][nx][ny]=d[p.z][p.x][p.y]+;
q.push(P(nz,nx,ny));
v[nz][nx][ny]=; }
} }
printf("Trapped!\n"); }
int main()
{
while(scanf("%d%d%d",&a,&b,&c)==,a||b||c){
int t=a;
int x,y,z;
memset(s,'\0', sizeof(s));// 一开始把x,y,z搞反了,调了好一会
for(int i=;i<t;i++){
for(int j=;j<b;j++){
scanf("%s",s[i][j]);
for(int k=;k<c;k++)
if(s[i][j][k]=='S') x=j,y=k,z=i;
}
}
bfs(P(z,x,y));
}
return ;
}
POJ 2251 三维BFS(基础题)的更多相关文章
- POJ:Dungeon Master(三维bfs模板题)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16748 Accepted: 6522 D ...
- poj 2251 三维地图最短路径问题 bfs算法
题意:给你一个三维地图,然后让你走出去,找到最短路径. 思路:bfs 每个坐标的表示为 x,y,z并且每个点都需要加上时间 t struct node{ int x, y, z; int t;}; b ...
- POJ 3320 尺取法(基础题)
Jessica's Reading Problem Description Jessica's a very lovely girl wooed by lots of boys. Recently s ...
- ZOJ - 3890 Wumpus(BFS基础题)
Wumpus Time Limit: 2 Seconds Memory Limit: 65536 KB One day Leon finds a very classic game call ...
- Poj(2225),三维BFS
题目链接:http://poj.org/problem?id=2225 这里要注意的是,输入的是坐标x,y,z,那么这个点就是在y行,x列,z层上. 我竟然WA在了结束搜索上了,写成了输出s.step ...
- POJ 2777 线段树基础题
题意: 给你一个长度为N的线段数,一开始每个树的颜色都是1,然后有2个操作. 第一个操作,将区间[a , b ]的颜色换成c. 第二个操作,输出区间[a , b ]不同颜色的总数. 直接线段树搞之.不 ...
- Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
随机推荐
- java 与操作系统进程同步问题(二)————经典消费者生产者问题
http://www.cnblogs.com/zyp4614/p/6033757.html (java 与操作系统进程同步问题(一)----互斥问题) 今天写的是最经典的生产者消费者问题,最简单的版本 ...
- 《HelloGitHub》第 14 期
公告 欢迎通过在 GitHub 上新建 issues 方式推荐项目,我真心希望读者可以在 HelloGItHub,找到真正的编程乐趣! <HelloGitHub>第 14 期 兴趣是最好的 ...
- TCP:三次握手、四次握手、backlog及其他
TCP是什么 首先看一下OSI七层模型: 然后数据从应用层发下来,会在每一层都加上头部信息进行封装,然后再发送到数据接收端,这个基本的流程中每个数据都会经过数据的封装和解封的过程,流程如下图所示: 在 ...
- python 字典的常见操作
字典 字典的增删改查 字典的创建方式: # 创建字典类型 info = { 'name':'李白', ', 'sex':'男' } msg = { 'user01':'Longzeluola', 'u ...
- fidder从基础到熟练
一.fidder介绍 1.Fiddler是一款由C#语言开发的免费http调试代理软件,有.net 2 和 .net 4 两种版本.Fiddler能够记录所有的你电脑和互联网之间的http通讯,Fid ...
- python List和String 转换注意
不能用str(list),t=['\x87\xe9\xa5\xb0\xef\xbc']In [28]: str(t)Out[28]: "['\\x87\\xe9\\xa5\\xb0\\xef ...
- leetcode算法题(JavaScript实现)
题外话 刷了一段时间的codewars的JavaScript题目之后,它给我最大的感受就是,会帮助你迅速的提升你希望练习的语言的API的熟悉程度,Array对象.String对象等原生方法,构造函数. ...
- sql拼接,String和Stringbuffer的问题
首先提出来一个问题: 下边两种拼字符串的方式,哪种更好一些,或者还有更好的方式? StringBuffer hql=new StringBuffer(); hql.append("from ...
- react-native学习(RN)--之Window环境下搭建环境配置
react-native以后会更火的,自从2015年facebook开源了Android 一.安装java 二.安装Android Studio 三.安装react-native需要的Android ...
- spingMVC aop不生效的解决方式
从网上搜索了一些资料,参考了下面的这个解决方案 http://blog.csdn.net/mmm333zzz/article/details/16858209