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

    ## 第三章 ### 今日内容 1.整型 2.布尔值 3.字符串 ​ 索引​ 切片​ 步长​ 字符串的方法 4.for循环 ### 1.整型 - python3:全部是整形- python2:整形,长 ...

  2. UEM“探针”技术及用户体验管理

    随着互联网产品越来越多,用户群体越来越庞大以及用户品位的多样性增加,我们会发现这样的一个规律,就是相同类型的产品,比如播放器中的QQ影音和暴风影音,再比如小游戏平台中的腾讯游戏和联众等等,他们的功能是 ...

  3. JS和C#.NET获取客户端IP

    我们经常在项目中会遇到这种需要获取客户端真实IP的需求,其实在网上也能随便就能查到各种获取的方法,我也是在网上查了加上了自己的实践,说一下自己在实践后的感受,基本上网上大部分都是用JS的方法来获取客户 ...

  4. cinder支持nfs快照

    [问题描述] cinder后端设置为NFS,磁盘创建快照失败. 日志里面发现了这个错误: VolumeDriverException: Volume driver reported an error: ...

  5. [转载]windows下mongodb安装与使用整理

    windows下mongodb安装与使用整理 一.首先安装mongodb 1.下载地址:http://www.mongodb.org/downloads 2.解压缩到自己想要安装的目录,比如d:\mo ...

  6. pythonday02基础与运算符

    今日概要 1.循环 2.字符串格式化 3.运算符 4.编码 if的嵌套 score = input('请输入成绩') score_int = int(score) if score_int >= ...

  7. python面试总结1(基础章节)

    python语言基础 语言特点 python是静态还是动态类型?是强类型还是弱类型 动态强类型语言 动态还是静态指的是编译期还是运作期确定类型 强类型指的是不会发生隐式类型转换 python作为后端语 ...

  8. React单页面应用使用antd的锚点跳转失效

    首先在react项目中引用antd的锚点 import {Anchor} from 'antd';const { Link } = Anchor; <Anchor> <Link hr ...

  9. 这些用来审计 Kubernetes RBAC 策略的方法你都见过吗?

    原文链接:这些用来审计 Kubernetes RBAC 策略的方法你都见过吗? 认证与授权对任何安全系统来说都至关重要,Kubernetes 也不例外.即使我们不是安全工作人员,也需要了解我们的 Ku ...

  10. Git 实用技巧:git stash

    我们经常会遇到这样的情况: 正在dev分支开发新功能,做到一半时有人过来反馈一个bug,让马上解决,但是新功能做到了一半你又不想提交,这时就可以使用git stash命令先把当前进度保存起来.然后切换 ...