[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. hdu1224SPFA求最长路加上打印路径

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1224/ 无负环. 代码如下: #include<bits/stdc++.h> using names ...

  2. 安装自动化测试工具webdriver与selenium模块

    webdriver是一个驱动,需要与selenium配合使用,selenium是自动化测试和爬虫的专业模块,对于不同的浏览器需要不同的webdriver,这里我用的是ubuntu19.10的系统,以p ...

  3. C#中的9个“黑魔法”与“骚操作”

    C#中的9个"黑魔法"与"骚操作" 我们知道C#是非常先进的语言,因为是它很有远见的"语法糖".这些"语法糖"有时过于好 ...

  4. h5 js数组Array方法总结

    重新复习数组方法. 一.首先说一下构建一个数组. 1.直接定义一个数组. var a = [1,2,3]; 2.通过Array 对象new一个数组,但Array对象根据传参的不同会返回不同的数组对象. ...

  5. Mysql 随笔记录

    Soundex 声音相似的 select * from demos where Soundex('title') = Soundex('标示'); Concat 拼接语句 select concat( ...

  6. Java构造器(构造方法/constructor)

    我们先来看一下什么是构造器: 1.构造器也叫构造方法或构造函数,分为有参构造器和无参构造器: 2.构造器也是一种方法,只不过是一种特殊的方法,它会在对象创建的时候被调用: 3.构造器最大的作用就是在创 ...

  7. Spring核心组件知识梳理

    Spring的一些概念和思想 Spring的核心:AOP.IOC. 简单点说,就是把对象交给Spring进行管理,通过面向切面编程来实现一些"模板式"的操作,使得程序员解放出来,可 ...

  8. [noip模拟]改造二叉树<LIS>

    1.改造二叉树 [题目描述] 小Y在学树论时看到了有关二叉树的介绍:在计算机科学中,二叉树是每个结点最多有两个子结点的有序树.通常子结点被称作“左孩子”和“右孩子”.二叉树被用作二叉搜索树和二叉堆.随 ...

  9. Jedis连接外部Redis

    Jedis连接外部Redis 1.在服务器开放端口redis默认6379,如果有宝塔面板则还需要在宝塔放行6379端口 2.修改redis.conf 注释掉 绑定IP 127.0.0.1 # bind ...

  10. 360网络安全学习笔记——SQLmap

    SQLmap简介 SQLmap是一个开源的自动化的SQL注入工具,其主要功能是扫描,发现并利用给定的URL的SQL注入漏洞. SQL注入模式 1.基于布尔的盲注 2.基于时间的盲注 3.基于报错注入 ...