[NWUACM] 
你被困在一个三维的空间中,现在要寻找最短路径逃生!
空间由立方体单位构成
你每次向上下前后左右移动一个单位需要一分钟
你不能对角线移动并且四周封闭
是否存在逃出生天的可能性?如果存在,则需要多少时间?

Input - 输入

  输入第一行是一个数表示空间的数量。
  每个空间的描述的第一行为L,R和C(皆不超过30)。
  L表示空间的高度。
  R和C分别表示每层空间的行与列的大小。
  随后L层地牢,每层R行,每行C个字符。
  每个字符表示空间的一个单元。'#'表示不可通过单元,'.'表示空白单元。你的起始位置在'S',出口为'E'。
  每层空间后都有一个空行。L,R和C均为0时输入结束。

Output - 输出

  每个空间对应一行输出。

  如果可以逃生,则输出如下

Escaped in x minute(s).

  x为最短脱离时间。

  如果无法逃生,则输出如下

Trapped!

Sample Input - 输入样例

3 4 5
S....
.###.
.##..
###.#
#####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0

Sample Output - 输出样例

Escaped in 11 minute(s).
Trapped! 思路:这个题目就是6个方向的BFS把 方向设定好,,找到起点找到终点,然后BFS吧
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstdio>
#include<cstring>
#define N 33
//int base[6][3] = { {-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1} };
using namespace std;
int l,n,m;
char arr[N][N][N];
int mark[N][N][N];
int sa,sb,sc;
int ea,eb,ec;
struct stu{
int a,b,c;//坐标
int s;//距离
}e1,e2,e3;
int base[][] = { {-,,},{,,},{,-,},{,,},{,,-},{,,} };//6个方向
void BFS(){
memset(mark,,sizeof(mark));
queue<stu >s;
e1.a=sa,e1.b=sb,e1.c=sc;
e1.s=;
s.push(e1);
mark[sa][sb][sc]=; int ans=-;
while(s.size()){
e2=s.front();
s.pop();
if(e2.a==ea && e2.b==eb && e2.c==ec)//判断是否到达了终点
{
ans=e2.s;
break;
}
for(int i=;i<;i++){
e3.a=e2.a+base[i][];
e3.b=e2.b+base[i][];
e3.c=e2.c+base[i][];
if((e3.a>= ) && (e3.a < l) && (e3.b >= ) && (e3.b < n) && (e3.c >= ) && (e3.c < m)
&& (!mark[e3.a][e3.b][e3.c]) && (arr[e3.a][e3.b][e3.c] == '.' || arr[e3.a][e3.b][e3.c] == 'E'))
{
e3.s=e2.s+;
mark[e3.a][e3.b][e3.c]=;
s.push(e3);
} }
}
if(ans==-){
cout<<"Trapped!"<<endl;
}
else {
printf("Escaped in %d minute(s).\n",ans);
}
} int main()
{
while(cin>>l>>n>>m){
if(n==&&m==&&l==)
break;
for(int i=;i<l;i++){
for(int j=;j<n;j++){
scanf("%s",&arr[i][j]);
}
}
for(int i=;i<l;i++){
for(int j=;j<n;j++){
for(int k=;k<m;k++){
if(arr[i][j][k]=='S')
{
sa=i;
sb=j;
sc=k;
}
else if(arr[i][j][k]=='E'){
ea=i;
eb=j;
ec=k;
}
}
}
}
BFS();
}
return ;
}

E - Dungeon Master BFS的更多相关文章

  1. hdu 2251 Dungeon Master bfs

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17555   Accepted: 6835 D ...

  2. POJ2251 Dungeon Master —— BFS

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  3. Dungeon Master bfs

    time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u POJ 2251 Descriptio ...

  4. 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 ...

  5. [poj] Dungeon Master bfs

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...

  6. poj 2251 Dungeon Master( bfs )

    题目:http://poj.org/problem?id=2251 简单三维 bfs不解释, 1A,     上代码 #include <iostream> #include<cst ...

  7. POJ 2251 Dungeon Master (BFS最短路)

    三维空间里BFS最短路 #include <iostream> #include <cstdio> #include <cstring> #include < ...

  8. POJ2251 Dungeon Master(bfs)

    题目链接. 题目大意: 三维迷宫,搜索从s到e的最小步骤数. 分析: #include <iostream> #include <cstdio> #include <cs ...

  9. POJ 2251 Dungeon Master bfs 难度:0

    http://poj.org/problem?id=2251 bfs,把两维换成三维,但是30*30*30=9e3的空间时间复杂度仍然足以承受 #include <cstdio> #inc ...

随机推荐

  1. hdu1175 连连看(bfs疯狂MLE和T,遂考虑dfs+剪枝)

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1175/ 题目大意就是给出地图,上面有若干的数,相当于连连看,给了q个查询,问给出的两个位置的数能否在两次转弯以内 ...

  2. 用sort 排序

    这两天看了一个比较好的sort总结,所以转载了一下 阅读目录 1.sort 2.sort简介 3.sort扩展 1.sort 使用:#include <algorithm>   using ...

  3. redis中setbit bitcount命令详解

    bitmap,位图,即是使用bit. redis字符串是一个字节序列. 1 Byte = 8 bit SETBIT key offset value 设置或者清空key的value(字符串)在offs ...

  4. Python第五章-内置数据结构01-字符串

    Python 内置的数据结构 ​ 到目前为止,我们如果想保存一些数据,只能通过变量.但是如果遇到较多的数据要保存,这个时候时候用变量就变的不太现实. ​ 我们需要能够保存大量数据的类似变量的东东,这种 ...

  5. 【笔记3-31】Python语言基础-序列sequence

    序列sequence 可变序列 列表 list 字典 不可变序列 字符串 str 元祖 tuple 通过索引修改列表 del 删除元素 del my_list[2] 切片赋值只能是序列 .insert ...

  6. mongodb_2

    一.游标 在mongodb中,底层使用js引擎进行各种操作,所以我们在命令行窗口,可直接执行js代码. #使用for循环,插入1000条数据. > for (var i=0;i<1000; ...

  7. Ubuntu 安装 tensorflow-gpu 1.4 包含 CUDA 8.0 和cuDNN

    硬件环境:NVIDIA GTX 980 Ti 系统环境:Ubuntu 16.04 64位 一.安装 NVIDIA驱动 关闭 Secure Boot 具体如何禁用 BIOS 中的 Secure Boot ...

  8. 【Pytest04】全网最全最新的Pytest框架fixture应用篇(2)

    一.Fixture参数之params参数可实现参数化:(可以为list和tuple,或者字典列表,字典元祖等) 实例如下: import pytest def read_yaml(): '] @pyt ...

  9. 使用node.js中遇到的一些小bug

    1.BUG Cannot set headers after they are sent to the client 解决:即发出一次请求得到两次或以上的回应时会出现此警告,此时注意查看再在一些条件下 ...

  10. CtenOS开放3306端口

    1.查看防火墙状态 2. 关闭防火墙firewall 3. 开启端口 4. 重启防火墙 5. 常用命令介绍 在 Centos 7 中防火墙由 firewalld 来管理,而不是 iptables. 1 ...