POJ 2251 Dungeon Master(三维空间bfs)
题意:三维空间求最短路,可前后左右上下移动。
分析:开三维数组即可。
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int MAXN = 30 + 10;
char pic[MAXN][MAXN][MAXN];
bool vis[MAXN][MAXN][MAXN];
int sx, sy, sz;
int dr[] = {0, 0, 1, -1, 0, 0};
int dc[] = {1, -1, 0, 0, 0, 0};
int dz[] = {0, 0, 0, 0, 1, -1};
int L, R, C;
bool judge(int x, int y, int z){
return x >= 0 && x < R && y >= 0 && y < C && z >= 0 && z < L;
}
int bfs(){
queue<int> x, y, z, step;
x.push(sx), y.push(sy), z.push(sz), step.push(0);
vis[sz][sx][sy] = true;
while(!x.empty()){
int tmpx = x.front(); x.pop();
int tmpy = y.front(); y.pop();
int tmpz = z.front(); z.pop();
int tmpstep = step.front(); step.pop();
for(int i = 0; i < 6; ++i){
int tx = tmpx + dr[i];
int ty = tmpy + dc[i];
int tz = tmpz + dz[i];
if(judge(tx, ty, tz)){
if(pic[tz][tx][ty] == 'E') return tmpstep + 1;
if(pic[tz][tx][ty] != '#' && !vis[tz][tx][ty]){
vis[tz][tx][ty] = true;
x.push(tx);
y.push(ty);
z.push(tz);
step.push(tmpstep + 1);
}
}
}
}
return -1;
}
int main(){
while(scanf("%d%d%d", &L, &R, &C) == 3){
if(!L && !R && !C) return 0;
memset(vis, false, sizeof vis);
for(int i = 0; i < L; ++i){
for(int j = 0; j < R; ++j){
scanf("%s", pic[i][j]);
for(int k = 0; k < C; ++k){
if(pic[i][j][k] == 'S'){
sz = i, sx = j, sy = k;
}
}
}
}
int ans = bfs();
if(ans == -1) printf("Trapped!\n");
else printf("Escaped in %d minute(s).\n", ans);
}
return 0;
}
POJ 2251 Dungeon Master(三维空间bfs)的更多相关文章
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ - 2251 Dungeon Master 【BFS】
题目链接 http://poj.org/problem?id=2251 题意 给出一个三维地图 给出一个起点 和 一个终点 '#' 表示 墙 走不通 '.' 表示 路 可以走通 求 从起点到终点的 最 ...
- poj 2251 Dungeon Master(bfs)
Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...
- (简单) POJ 2251 Dungeon Master,BFS。
Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...
- POJ 2251 Dungeon Master【BFS】
题意:给出一个三维坐标的牢,给出起点st,给出终点en,问能够在多少秒内逃出. 学习的第一题三维的广搜@_@ 过程和二维的一样,只是搜索方向可以有6个方向(x,y,z的正半轴,负半轴) 另外这一题的输 ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- 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 ...
随机推荐
- RabbitMq学习笔记——MingW编译RabbitMQ C
1.安装cmak,下载地址:https://cmake.org/download/,当前最新版本3.15.1,下载cmake-3.15.1-win64-x64.msi 注意:安装时勾选将bin目录添加 ...
- shell和Makefile
一.shell基础 1.shell介绍 shell是操作系统的终端命令行 意义:快速的编译多个.c文件 shell是一类编程语言 常用shell语言:sh.bash.csh.ksh.perl.pyth ...
- 093、Java中String类之字符串是匿名对象
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- greenplum 导入数据方式
参考: http://gpdb.docs.pivotal.io/4390/admin_guide/load/topics/g-working-with-file-based-ext-tables.ht ...
- Liveness 探测【转】
Liveness 探测让用户可以自定义判断容器是否健康的条件.如果探测失败,Kubernetes 就会重启容器. 还是举例说明,创建如下 Pod: 启动进程首先创建文件 /tmp/healthy,30 ...
- sql 经纬度范围检索(谷歌方案)
SELECT id, ( * acos ( //公里: 6371 英里: 3959 cos ( radians(78.3232) ) * cos( radians( 数据库纬度字段) ) * cos( ...
- 解决win10创建Django工程,运行django-admin.py startproject 工程名,失败的问题
在看我这篇教程的前提是你应该已经正确装好python和Django了,好了,废话不说了,正题走你!你现在是不是很纠结自己运行django-admin.py startproject 工程名 ...
- jenkins#自动构建并部署springboot的jar包
1.GitLab 8.0.0(版本比较低,配置比较简单) 配置 点击项目 --> settings --> web Hooks 2.jenkins配置
- Day8 - G - Bound Found ZOJ - 1964
Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...
- 7.4 Varnish VCL的子程序