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 ...
随机推荐
- MySQL 导出远程服务器数据库 为 sql文件
MySQL 导出远程服务器sql文件 mysqldump -h192.168.1.111 –P3306 -uroot -ppassword --default-character-set=utf8 t ...
- 搭建高可用mysql系列(1)-- Percona XtraDB Cluster介绍
Percona XtraDB Cluster (下文简称PXC)是一个开源的mysql 高可用解决方案.它将Percona Server和Percona XtraBackup与Galera库集成在一起 ...
- Js 面向对象之封装,继承,原型,原型链
封装 ,继承 ,原型, 原型链 封装 ? 面向对象有三大特性,封装.继承和多态.对于ES5来说,没有class(类)的概念,并且由于JS的函数级作用域(函数内部的变量在函数外访问不到),所以我们就可以 ...
- msf提权基础(一)
令牌(token)相当于系统的临时密钥(账号及密码) 加载incognito模块 meterpreter> use incognito meterpreter > list_tokens ...
- C# 生成自签名CA证书
"; string signatureAlgorithm = "SHA1WithRSA"; // Generate RSA key pair var rsaGenerat ...
- crontab定时执行
一.crond简介 crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动cro ...
- 关于EasyPoi导出Excel
如果你觉得Easypoi不好用,喜欢用传统的poi,可以参考我的这篇博客:Springmvc导出Excel(maven) 当然了,万变不离其宗.Easypoi的底层原理还是poi.正如MyBatis ...
- ZOJ 3872 浙江2015年省赛试题
D - Beauty of Array Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...
- STM32F103 ucLinux开发BOOT
STM32F103 ucLinux开发BOOT STM3210E-EVAL官方开发板主芯片STM32F103ZET6: 片内512K Flash,地址0x0800 0000 ~ 0x0807 FFFF ...
- 如何在C#程序中模拟域帐户进行登录操作 (转载)
.NET Core .NET Core也支持用PInvoke来调用操作系统底层的Win32函数 首先要在项目中下载Nuget包:System.Security.Principal.Windows 代码 ...