POJ2251-Dungeon Master(3维BFS)
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!
//题意:
//相当于一栋大楼里面很多秘密通道,
//S是起始位置,E是终点位置,
//‘#’是墙,‘.’是路,问从S出发最少经过多长时间就到达E处;
//
//分析:
//和迷宫不同的是,迷宫是平面上东南西北的移动,
//相当于在大楼里面的一层楼里找出口,而这个题目在迷宫的基础上又增加了上下的移动,
//即大楼里面的上下层之间的移动,
//所以需要建立三维的数组,找到S的位置,
//移动方向由4个增加到6个,直到找到E为止,如果找遍了所有的能走的地方都没找到出口E,就出不来了!!!
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
int zz, xx, yy, tx, ty, tz;
int start_x, start_y, start_z, end_x, end_y, end_z;
char ch;
int map[][][];
int book[][][]; int d[][] ={-,,,,,,,-,,,,,,,,,,-}; struct node{
int x,y,z;
int step;
}q; void BFS(){
q.x = start_x,q.y = start_y,q.z = start_z;
q.step = ;
queue<node>qq;
qq.push(q);
book[start_x][start_y][start_z] = ;
while(!qq.empty()){
node t = qq.front();
qq.pop(); // cout<<" x y z ="<<t.x<<" "<<t.y<<" "<<t.z<<endl;
if(t.x==end_x && t.y==end_y && t.z == end_z){
cout<<"Escaped in "<<t.step<<" minute(s)."<<endl;
return;
}
for( int i = ; i < ; i++ ) { tz = t.z + d[i][];
tx = t.x + d[i][];
ty = t.y + d[i][];
if( tz>zz||tz< || tx>xx||tx< || ty>yy||ty< ) continue;
if( map[tz][tx][ty] == && book[tz][tx][ty]== ){
node temp;
book[tz][tx][ty]=;
temp.z = tz, temp.x = tx, temp.y = ty;
temp.step = t.step + ;
qq.push(temp);
}
}
}
cout<<"Trapped!"<<endl;
return;
} int main() {
while(scanf("%d%d%d",&zz,&xx,&yy),zz+xx+yy)
{ for( int i = ; i <= zz; i++ ) {
for( int j = ; j <= xx; j++ ) {
for( int k = ; k <= yy; k++ ) {
cin>>ch;
switch(ch){
case 'S':start_z = i,start_x = j,start_y = k; break;
case 'E':end_z = i, end_x = j, end_y = k; break;
case '.':map[i][j][k] = ;break;
case '#':map[i][j][k] = ;break;
}
}
}
}
memset(book,,sizeof(book));
BFS();
}
return ;
}
POJ2251-Dungeon Master(3维BFS)的更多相关文章
- poj 2251 Dungeon Master 3维bfs(水水)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21230 Accepted: 8261 D ...
- POJ2251——Dungeon Master(三维BFS)
和迷宫问题区别不大,相比于POJ1321的棋盘问题,这里的BFS是三维的,即从4个方向变为6个方向. 用上队列的进出操作较为轻松. #include<iostream> #include& ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- POJ - 2251 Dungeon Master 多维多方向BFS
Dungeon Master You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is ...
- BFS POJ2251 Dungeon Master
B - Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- 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模板】
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...
- 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 ...
- Dungeon Master(三维bfs)
题目链接:http://poj.org/problem?id=2251 题目: Description You are trapped in a 3D dungeon and need to find ...
随机推荐
- CentOs7.2编译安装Nginx服务器
1. 安装nginx依赖 首先安装nginx的依赖 yum install gcc gcc-c++ openssl openssl-devel cyrus-sasl-md5 2,创建nginx用户 如 ...
- 1066. [SCOI2007]蜥蜴【最大流】
Description 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃 到边界外. 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴可以跳到 ...
- juquery去除字符串前后的空格
1. 去掉字符串前后所有空格: 代码如下: function Trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); }
- Linux 无法连接网络排查方法
.hosts文件增加 127.0.0.1 对localhost的解析. .检查/etc/resove.cnf dns配置是否正确 .route命令检查是否有默认路由,没有就 route add 网段 ...
- Kafka设计解析(六)Kafka高性能架构之道
转载自 技术世界,原文链接 Kafka设计解析(六)- Kafka高性能架构之道 本文从宏观架构层面和微观实现层面分析了Kafka如何实现高性能.包含Kafka如何利用Partition实现并行处理和 ...
- 【转载】Caffe + Ubuntu 14.04 + CUDA 6.5 新手安装配置指南
洋洋洒洒一大篇,就没截图了,这几天一直在折腾这个东西,实在没办法,不想用Linux但是,为了Caffe,只能如此了,安装这些东西,遇到很多问题,每个问题都要折磨很久,大概第一次就是这样的.想想,之后应 ...
- K2 4.7 升级 数据库排序规则更改
介绍 在过去,K2没有指定安装过程中要在其数据库上使用的标准排序规则.然而,现在K2引入了标准排序规则,以便在之后使用(如果我没有错的话,它是在4.7). 因此, 问题出现在数据库的排序规则不是Lat ...
- K2 BPM介绍(2)
K2 BPM介绍(2) 上一篇已经讲了一些K2 BPM基本特性,本遍讲K2 BPM大概的组件以及组件关系. K2 BPM组件 K2 BPM分别由以下组件构成: K2产品已经发展很多年,所以它有很多版本 ...
- Hadoop源码分析(mapreduce.lib.partition/reduce/output)
Map的结果,会通过partition分发到Reducer上.Reducer做完Reduce操作后,通过OutputFormat,进行输出.以下我们就来分析參与这个过程的类. Mapper的结果, ...
- 【原型图】Mockplus
Mockplus 原型设计工具