You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.

Is an escape possible? If yes, how long will it take?

Input

The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size). 
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

Each maze generates one line of output. If it is possible to reach the exit, print a line of the form

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! 代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=1e5+;
typedef long long ll;
char Map[][][];
int vis[][][];
struct node
{
int x,y,z;
int cnt;
};
using namespace std;
int sx,sy,sz;
int ex,ey,ez;
int dir[][]={{,,},{,,-},{-,,},{,,},{,,},{,-,}};
int s;
bool check(int x,int y,int z)
{
if((Map[z][x][y]=='.'||Map[z][x][y]=='E')&&vis[z][x][y]==)
{
return true;
}
else
{
return false;
}
}
bool bfs()
{
node start;
start.x=sx;
start.y=sy;
start.z=sz;
start.cnt=;
queue<node>q;
q.push(start);
vis[sz][sx][sy]=;
while(!q.empty())
{
node now=q.front();
q.pop();
//printf("%d %d %d\n",now.z,now.x,now.y);
if(now.z==ez&&now.x==ex&&now.y==ey)
{
s=now.cnt;
return true;
}
for(int t=;t<;t++)
{
node next;
next.x=now.x+dir[t][];
next.y=now.y+dir[t][];
next.z=now.z+dir[t][];
next.cnt=now.cnt+;
if(check(next.x,next.y,next.z))
{
vis[next.z][next.x][next.y]=;
q.push(next);
} }
}
return false;
}
int main()
{
int L,R,C;
while(scanf("%d%d%d",&L,&R,&C)!=EOF)
{
memset(vis,,sizeof(vis));
if(L==&&R==&&C==)
{
break;
}
s=;
for(int t=;t<L;t++)
{
for(int j=;j<R;j++)
{
scanf("%s",Map[t][j]);
}
}
for(int t=;t<L;t++)
{
for(int j=;j<R;j++)
{
for(int k=;k<C;k++)
{
if(Map[t][j][k]=='S')
{
sx=j;
sy=k;
sz=t;
}
if(Map[t][j][k]=='E')
{
ex=j;
ey=k;
ez=t;
}
}
}
} if(bfs())
printf("Escaped in %d minute(s).\n",s);
else
{
printf("Trapped!\n");
}
} return ;
}

Dungeon Master(三维bfs)的更多相关文章

  1. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  2. POJ 2251 Dungeon Master (三维BFS)

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

  3. POJ:Dungeon Master(三维bfs模板题)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16748   Accepted: 6522 D ...

  4. ZOJ 1940 Dungeon Master 三维BFS

    Dungeon Master Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Desc ...

  5. UVa532 Dungeon Master 三维迷宫

        学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时)   #i ...

  6. 【POJ - 2251】Dungeon Master (bfs+优先队列)

    Dungeon Master  Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...

  7. 棋盘问题(DFS)& Dungeon Master (BFS)

    1棋盘问题 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的 ...

  8. Dungeon Master (简单BFS)

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

  9. POJ 2252 Dungeon Master 三维水bfs

    题目: http://poj.org/problem?id=2251 #include <stdio.h> #include <string.h> #include <q ...

随机推荐

  1. 畅购商城(八):微服务网关和JWT令牌

    好好学习,天天向上 本文已收录至我的Github仓库DayDayUP:github.com/RobodLee/DayDayUP,欢迎Star,更多文章请前往:目录导航 畅购商城(一):环境搭建 畅购商 ...

  2. 使用HttpClient 发送 GET、POST(FormData、Raw)、PUT、Delete请求及文件上传

    httpclient4.3.6 package org.caeit.cloud.dev.util; import java.io.File; import java.io.IOException; i ...

  3. 在龙芯mips64el平台编译bmon

    bmon 是一个 实时命令行流量监控软件,但作者在github并没有提供mips64el的版本.下面记录一下编译过程.可以在这里下载bmon.v4.0.linux-mips64el.tar.gz. 环 ...

  4. 【lhyaaa】2020深圳大湾区比赛总结

    又名花样丢分锦集 首先,我们需要来吐槽一下垃圾szccf,毁我青春 居然没有提醒不能用万能头文件,导致一题爆0,据说还有一些结果不是自己答的 emmm-- 进正题 选择题 对包含n个数的序列进行冒泡排 ...

  5. pytorch载入模型的参数总是变化,比如说某个conv(3,3)kernel的几个参数总是变化:

  6. CTFhub-WEB前置-http协议闯关

    前情提要: 在渗透学习过程中,web的基础知识很重要,在这里通过long long ago之前学习的http基础,并结合网上的CTFhub--WEB前置之http协议闯关,对web基础知识进行加固并查 ...

  7. 阿里云体验实验室 教你如何《快速搭建LNMP环境》

    ## 体验平台简介 面向开发者和中小企业打造的一站式.全云端的开发平台,打开浏览器就可以开发.调试.上线,所测即所得,并结合无服务器的模式,重新定义云原生时代的研发工作方法论.旨在降低开发者上手成本和 ...

  8. 如何隐藏win32 控制台程序的console窗口 2011-06-17 17:59

    加上 即可 // 隐藏窗口#pragma   comment(linker,   "/subsystem:\"windows\"  /entry:\"mainC ...

  9. 一个简单的RPC框架实现

    package com.rpc; public interface EchoService { String echo(String ping); } package com.rpc; public ...

  10. PYTHON替代MATLAB在线性代数学习中的应用(使用Python辅助MIT 18.06 Linear Algebra学习)

    前言 MATLAB一向是理工科学生的必备神器,但随着中美贸易冲突的一再升级,禁售与禁用的阴云也持续笼罩在高等学院的头顶.也许我们都应当考虑更多的途径,来辅助我们的学习和研究工作. 虽然PYTHON和众 ...