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! 三维bfs水题,但鉴于自己好久没有做bfs,忘记了vis数组放哪里和取值,最最重要的是中间一行代码写错了,害我debug半天
bfs模板题
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
int dx[]={,,-,,,},dy[]={,-,,,,},dz[]={,,,,,-};
int t,n,m,sx,sy,sz,ex,ey,ez,vis[][][];
char mapn[][][];
struct node{
int x,y,z,step;
};
void bfs(){
node p;
p.x = sx,p.y = sy,p.z = sz;
vis[sx][sy][sz] = ;
p.step = ;
queue<node> q;
q.push(p);
while(!q.empty()){
node tmp = q.front();
q.pop();
if(tmp.x == ex && tmp.y == ey && tmp.z == ez){
cout << "Escaped in " << tmp.step << " minute(s)." << endl;
return;
}
for(int i=;i<;i++){
int xx = tmp.x + dx[i];
int yy = tmp.y + dy[i];
int zz = tmp.z + dz[i];
if(mapn[xx][yy][zz] != '#' && xx> && xx<=t && yy> && yy<=n && zz> && zz<=m && !vis[xx][yy][zz]){
node tp;
tp.x = xx;
tp.y = yy;
tp.z = zz;
tp.step = tmp.step + ;//这一行代码,开始写成了tp.step++;
vis[xx][yy][zz] = ;
q.push(tp);
}
}
}
cout << "Trapped!" << endl;
}
int main(){
while(cin >> t >> n >> m){
if(t == || n == || m == ){
break;
}
memset(vis,,sizeof(vis));
for(int i=;i<=t;i++){
for(int j=;j<=n;j++){
for(int k=;k<=m;k++){
cin >> mapn[i][j][k];
if(mapn[i][j][k] == 'S'){
sx = i,sy = j,sz = k;
}
if(mapn[i][j][k] == 'E'){
ex = i,ey = j,ez = k;
}
}
}
}
bfs();
}
return ;
}

Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索的更多相关文章

  1. 迷宫问题 POJ - 3984 [kuangbin带你飞]专题一 简单搜索

    定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...

  2. Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索

    Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...

  3. 棋盘问题 POJ - 1321 [kuangbin带你飞]专题一 简单搜索

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

  4. [kuangbin带你飞]专题一 简单搜索(回顾)

    A - 棋盘问题 POJ - 1321 注意条件:不能每放一个棋子,就标记一行和一列,我们直接枚举每一行就可以了. AC代码: #include<iostream> #include< ...

  5. [kuangbin带你飞]专题一 简单搜索

            ID Origin Title 454 / 1008 Problem A POJ 1321 棋盘问题   328 / 854 Problem B POJ 2251 Dungeon Ma ...

  6. [kuangbin带你飞]专题一 简单搜索 - B - Dungeon Master

    #include<iostream> #include<cstdio> #include<string> #include<vector> #inclu ...

  7. [kuangbin带你飞]专题一 简单搜索 题解报告

    又重头开始刷kuangbin,有些题用了和以前不一样的思路解决.全部题解如下 点击每道题的标题即可跳转至VJ题目页面. A-棋盘问题 棋子不能摆在相同行和相同列,所以我们可以依此枚举每一行,然后标记每 ...

  8. [kuangbin带你飞]专题一 简单搜索 x

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

  9. [kuangbin带你飞]专题一 简单搜索 - E - Find The Multiple

    //Memory Time //2236K 32MS #include<iostream> using namespace std; ]; //保存每次mod n的余数 //由于198的余 ...

随机推荐

  1. Downgrade extraction on phones running Android 7/8/9

    Now it's more and more difficult for forensic tools to extract evidence from smartphone running Andr ...

  2. 使用 Netty 实现一个 MVC 框架

    NettyMVC 上面介绍 Netty 能做是什么时我们说过,相比于 SpringMVC 等框架,Netty 没提供路由等功能,这也契合和 Netty 的设计思路,它更贴近底层.下面我们在 Netty ...

  3. C# 在某个线程上创建的控件不能成为在另一个线程上创建的控件的父级

    //使用委托进行修改UI界面 if (this.InvokeRequired) { this.Invoke(new MethodInvoker(delegate { createList(); })) ...

  4. (15)ASP.NET Core Web主机(IWebHostBuilder)

    1.前言 ASP.NET Core应用程序可以配置和启动主机(Host).主机负责应用程序启动和生存期管理,配置服务器和请求处理管道.主机还可以设置日志记录.依赖关系注入和配置.而host主机又包括W ...

  5. Java中...的作用

    Java中...的作用,代表接收若干个相同类型的参数 public void testFunction(int...arr){    //接收若干个int类型的参数     for (int i:ar ...

  6. Redis回顾

    之前有两篇文章着重介绍了redis集群的搭建和redis与spring的整合,一个月过去了,现在有些忘记了,今天又拿过来稳固一下,发现有很多的东西都忘记了. 资料汇总下载 首先安装ruby环境 安装过 ...

  7. Linux--shell重定向与文件处理命令--02

    一.IO重定向 1.数据输入:键盘---标准输入,但并不是唯一输入方式 ” | passwd –stdin username #同时添加用户和密码 while line;do 循环体...$line ...

  8. XAMPP/LAMPP到底在哪里启用APACHE2的rewrite

    XAMPP/LAMPP是一套我们在个人建站过程中非常便捷常用的集成环境.特别是对于学习PHP开发和建站非常便捷. 最近在使用CentOS7环境下的XAMPP过程中,遇到了一个问题,也就是apache2 ...

  9. 7.17 正则表达式 re模块

    在介绍正则表达式和re模块之前,先简要介绍一下 正则表达式与re模块的关系 1.正则表达式是一门独立的技术,任何语言均可使用 2.python中要想使用正则表达式需要通过re模块 正则表达式 元字符 ...

  10. HTTP与HTTPS之面试必备

    本文主要讲解Http与https的区别,以及https是怎样加密来保证安全的. 首先讲这俩个协议的简单区别: HTTP:超文本传输协议. HTTPS:安全套接字层超文本传输协议HTTP+SSL HTT ...