Description

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"queue"
#include"cstring"
using namespace std;
const int MAXN=;
char dun[MAXN][MAXN][MAXN];
int vis[MAXN][MAXN][MAXN];
struct node{
int L,R,C;
int step;
node(int l,int r,int c,int s):L(l),R(r),C(c),step(s){}
node(){}
};
int l,r,c;
int sl,sr,sc;
int el,er,ec;
int dl[]={,,,,,-};
int dc[]={,,,-,,};
int dr[]={,,,,-,};
int bfs()
{
queue<node> que;
que.push(node(sl,sr,sc,));
vis[sl][sr][sc]=;
while(!que.empty())
{
node now=que.front();que.pop();
if(now.L==el&&now.R==er&&now.C==ec)
{
return now.step;
}
for(int i=;i<;i++)
{
int nl=now.L+dl[i];
int nr=now.R+dr[i];
int nc=now.C+dc[i];
if(<=nl&&nl<l&&<=nr&&nr<r&&<=nc&&nc<c&&!vis[nl][nr][nc]&&dun[nl][nr][nc]!='#')
{
vis[nl][nr][nc]=;
que.push(node(nl,nr,nc,now.step+));
}
}
}
return -;
}
int main()
{
while(scanf("%d%d%d",&l,&r,&c)!=EOF&&l!=)
{
memset(vis,,sizeof(vis));
scanf("%*c");
for(int i=;i<l;i++)
{
for(int j=;j<r;j++)
{
for(int z=;z<c;z++)
{
scanf("%c",&dun[i][j][z]);
if(dun[i][j][z]=='S')
{
sl=i,sr=j,sc=z;
}
if(dun[i][j][z]=='E')
{
el=i,er=j,ec=z;
}
}
scanf("%*c");
}
scanf("%*c");
} int ans=bfs();
if(ans!=-)
{
printf("Escaped in %d minute(s).\n",ans);
}
else
{
printf("Trapped!\n");
}
}
return ;
}

virtual judge(专题一 简单搜索 B)的更多相关文章

  1. virtual judge(专题一 简单搜索 E)

    Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...

  2. virtual judge(专题一 简单搜索 C)

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

  3. virtual judge(专题一 简单搜索 A)

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

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

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

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

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

  6. kuangbin专题 专题一 简单搜索 Oil Deposits HDU - 1241

    题目链接:https://vjudge.net/problem/HDU-1241 题意:问有几个油田,一个油田由相邻的‘@’,组成. 思路:bfs,dfs都可以,只需要遍历地图,遇到‘@’,跑一遍搜索 ...

  7. kuangbin专题 专题一 简单搜索 迷宫问题 POJ - 3984

    题目链接:https://vjudge.net/problem/POJ-3984 这个题目,emm,上代码,看的估计应该是刚开始接触搜索的,我带点注释,你能慢慢理解. #include <ios ...

  8. kuangbin专题 专题一 简单搜索 Fire! UVA - 11624

    题目链接:https://vjudge.net/problem/UVA-11624 题意:一个迷宫,可能有一个或者多个地方着火了,每过1个时间消耗,火会向四周蔓延,问Joe能不能逃出迷宫,只要走出迷宫 ...

  9. kuangbin专题 专题一 简单搜索 Fliptile POJ - 3279

    题目链接:https://vjudge.net/problem/POJ-3279 题意:格子有两面,1表示黑色格子,0表示白色格子,奶牛每次可以踩一个格子,踩到的格子和它周围的上下左右格子都会翻面,也 ...

随机推荐

  1. ubuntu 17 编译BTCoin

    一. 安装开发环境 sudo apt-get update sudo apt-get install build-essential libtool autotools-dev autoconf pk ...

  2. Lock和Condition

    1 什么是可重入锁 可重入锁是说一个线程在已经获取了该锁的情况下,还可以再次获取该锁. 主要的应用场景: 可重入锁指的是在一个线程中可以多次获取同一把锁,比如:一个线程在执行一个带锁的方法,该方法中又 ...

  3. LookAndFeelInfo

    在读zap源码的时候碰到:UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());以下来自百度知道UIManager.s ...

  4. [转】IIS:Do not nest virtual directories

    原文:https://msdn.microsoft.com/en-us/library/ms178685.aspx#Anchor_6 Configuration settings for virtua ...

  5. js面对对象编程

    说到js,非常大一部分人会说我非常熟悉,在日常的web开发中经经常使用,那么你的js代码是符合面对对象思路的吗?那你会问我面向过程的js代码有什么不好吗?我的感受是面对对象的js编码更加简洁,降低了混 ...

  6. linux c编程:FIFO

    前面介绍的pipe属于匿名管道 管道的主要局限性正体现在它的特点上: 只支持单向数据流: 只能用于具有亲缘关系的进程之间: 没有名字: 管道的缓冲区是有限的(管道制存在于内存中,在管道创建时,为缓冲区 ...

  7. Android系统字体规范

    我们在做Android移动APP设计的时候,字号的选择也是很让人头疼,转载一份有关Android系统字体规范,如果在做Android项目的用户应该看看,如果有任何建议欢迎在留言处与我们交流探讨. 主要 ...

  8. Iptalbes练习题(二)

    接着上节,上节课,基本功能设置后,现在我们telnet本机一下,发现问题: [root@test1 ~]# telnet Trying 127.0.0.1... telnet: connect to ...

  9. 移动端web常见问题解决方案

    meta基础知识 H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 忽略将页面中的数字识别为电话号码 忽略Android平台中对邮箱地址的识别 当网站添加到主屏幕快速启动方式,可隐藏地址栏,仅针对i ...

  10. Ubuntu 16.04更换源

    Ubuntu 16.04下载软件速度有点慢,因为默认的是从国外下载软件,那就更换到国内比较好的快速更新源(就是这些软件所在的服务器),一般直接百度Ubuntu更新源就能出来一大堆,这时候最好是找和自己 ...