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层 ...
随机推荐
- Python教程(1.1)——配置Python环境
在正式开始学习Python之前我们需要先配置好Python环境. Python Python可以从Python官方网站上,选择适合你的操作系统的版本下载.下载完之后,运行下载的可执行文件进行安装. 这 ...
- sql备份(.mdf文件备份)
第一步: 右键需要备份的数据库(这里以MyDB为例),选择“属性”. 第二步: 选择“文件”,复制路径 第三步: 打开文件所在目录,复制MyDB.mdf和MyDB_log.ldf 第四步: 把数据库停 ...
- MySQL存储汉字
之前在网上查找了很多方法,排在前排的都是修改配置文件my.ini的,没有成功,后来找到了一个解决方法: 在建表的时候,在语句后面加上段"engine = innodb default cha ...
- 做一枚精致的程序猿,Fighting!
这几天我和我们的团队正在做一个公司管理系统的项目,团队分工根据成员的水平高低来分工,这样看似公平,但其实不公平,如此这样一来,那些水平稍不如别人的成员就没有发展的机会?那么问题来了,对于水平稍逊色的程 ...
- jsonp跨域再谈
昨天面试雷锋网,问到了jsonp跨域的问题,其实这个问题之前就会的,没有多大的深入,记得有一个名词在跨域中出现,就是同源机制, JavaScript是一种在Web开发中经常使用的前端动态脚本技术.在J ...
- 修改cms版权等等信息
目的:为DedeCMS换上精美多样的提示信息窗口 用到的开源项目:DedeCMS,artdialog 步骤: 1.下载include.rar文件完成后,解压得到2个php文件和一个使用说明文件,将ph ...
- 软件测试基础(软件测试分类和工具组)firebug、firepath的安装
白盒测试:需要了解内部结构和代码 黑盒测试:不关心内部结构和代码 灰盒测试:介于白盒黑盒之间 静态测试:测试时不执行被测试软件 动态测试:测试时执行被测试软件 单元测试:测试软件的单元模块 集成测试: ...
- 隐马尔科夫模型HMM(四)维特比算法解码隐藏状态序列
隐马尔科夫模型HMM(一)HMM模型 隐马尔科夫模型HMM(二)前向后向算法评估观察序列概率 隐马尔科夫模型HMM(三)鲍姆-韦尔奇算法求解HMM参数 隐马尔科夫模型HMM(四)维特比算法解码隐藏状态 ...
- HTTPS协议入门
目录什么是https?https的利与弊?https的原理和流程?什么是证书/CA证书?什么是单向SSL认证与双向SSL认证?网站如何实现https?网站实现https的一些补充说明参考网页 一.什么 ...
- Java模拟http请求调用远程接口工具类
package ln; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamRea ...