Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 32684   Accepted: 12529

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!

Source

解题思路:只是把二维的变成三维的了,本质上不变,就增加了两个方向。
但我还是卡了好久,我刚开始只记录了上一步的位置,不往上一步的位置走,结果一直超时。
后来发现只要走过的地方就把vis数组置为1,以后就不能走到这个位置了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue> using namespace std; struct node{
int x,y,z;
int step;
}; int l,r,c;
char maze[][][];
int vis[][][];
node start;
node endd;
int directx[]={,,,,,-};
int directy[]={-,,,,,};
int directz[]={,,-,,,}; int findd(){
queue<node> que;
memset(vis,,sizeof(vis));
start.step=;
que.push(start);
while(!que.empty()){
node now=que.front();
que.pop();
for(int i=;i<;i++){
node next=now;
next.x+=directx[i];
next.y+=directy[i];
next.z+=directz[i];
int xx=next.x;
int yy=next.y;
int zz=next.z;
if(maze[xx][yy][zz]=='#'||vis[xx][yy][zz]||!(xx>=&&xx<l&&yy>=&&yy<r&&yy>=&&zz>=&&zz<c)){
continue;
}
if(maze[xx][yy][zz]=='E'){
next.step+=;
return next.step;
}
if(maze[xx][yy][zz]=='.'){
next.step+=;
vis[xx][yy][zz]=;
que.push(next);
}
}
}
return ;
} int main()
{
while(scanf("%d %d %d",&l,&r,&c)&&(l+r+c!=)){
getchar();
for(int i=;i<l;i++,getchar()){
for(int j=;j<r;j++,getchar()){
for(int k=;k<c;k++){
scanf("%c",&maze[i][j][k]);
if(maze[i][j][k]=='S'){
start.x=i;
start.y=j;
start.z=k;
}
}
}
}
int ans=findd();
if(ans){
printf("Escaped in %d minute(s).\n",ans);
}else{
printf("Trapped!\n");
} } return ;
}

poj2251_kuagnbin带你飞专题一的更多相关文章

  1. 【算法系列学习三】[kuangbin带你飞]专题二 搜索进阶 之 A-Eight 反向bfs打表和康拓展开

    [kuangbin带你飞]专题二 搜索进阶 之 A-Eight 这是一道经典的八数码问题.首先,简单介绍一下八数码问题: 八数码问题也称为九宫问题.在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的 ...

  2. [kuangbin带你飞]专题1-23题目清单总结

    [kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...

  3. [kuangbin带你飞]专题十 匹配问题

        A-L 二分匹配 M-O 二分图多重匹配 P-Q 二分图最大权匹配 R-S 一般图匹配带花树 模板请自己找     ID Origin Title   61 / 72 Problem A HD ...

  4. [kuangbin带你飞]专题十 匹配问题 一般图匹配

    过去做的都是二分图匹配 即 同一个集合里的点 互相不联通 但是如果延伸到一般图上去 求一个一般图的最大匹配 就要用带花树来解决 带花树模板 用来处理一个无向图上的最大匹配 看了一会还是不懂  抄了一遍 ...

  5. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  6. [kuangbin带你飞]专题八 生成树 - 次小生成树部分

    百度了好多自学到了次小生成树 理解后其实也很简单 求最小生成树的办法目前遇到了两种 1 prim 记录下两点之间连线中的最长段 F[i][k] 之后枚举两点 若两点之间存在没有在最小生成树中的边 那么 ...

  7. [kuangbin带你飞]专题六 最小生成树

    学习最小生成树已经有一段时间了 做一些比较简单的题还算得心应手..花了三天的时间做完了kuangbin的专题 写一个题解出来记录一下(虽然几乎都是模板题) 做完的感想:有很多地方都要注意 n == 1 ...

  8. [kuangbin带你飞]专题十五 数位DP

            ID Origin Title   62 / 175 Problem A CodeForces 55D Beautiful numbers   30 / 84 Problem B HD ...

  9. [kuangbin带你飞]专题十 匹配问题 二分图多重匹配

    二分图的多重匹配问题不同于普通的最大匹配中的"每个点只能有最多一条边" 而是"每个点连接的边数不超过自己的限定数量" 最大匹配所解决的问题一般是"每个 ...

随机推荐

  1. wireshark解析自定义的protobuf协议

    先看最终效果 wireshark是开源的,而且在Windows下安装时用的是64位,所以相应的库文件需要使用64位. 一个Lua插件的Dissector结构大致如下: do -- 协议名称为 m_Me ...

  2. Asp.Net Core获取请求上下文HttpContext

    注:特别说明当前版本对应.Net Core2.1意义上框架 一.注入HttpContextAccessor ASP.NET Core中提供了一个IHttpContextAccessor接口,HttpC ...

  3. 用GO开发企业级分布式云存储系统

    一.基础架构 二.开发工具

  4. Excel 驼峰表达式

    =LEFT(A1,1)&MID(SUBSTITUTE(PROPER(A1),"_",""),2,100)

  5. Android必学之数据适配器BaseAdapter

    什么是数据适配器? 下图展示了数据源.适配器.ListView等数据展示控件之间的关系.我们知道,数据源是各种各样的,而ListView所展示数据的格式则是有一定的要求的.数据适配器正是建立了数据源与 ...

  6. 使用http load测试qps

    官网 http://acme.com/software/http_load/ 安装 wget http://acme.com/software/http_load/http_load-12mar200 ...

  7. git reflog

    http://www.softwhy.com/article-8573-1.html https://www.cnblogs.com/irocker/p/git-reflog.html https:/ ...

  8. 基于netty实现的长连接,心跳机制及重连机制

    技术:maven3.0.5 + netty4.1.33 + jdk1.8   概述 Netty是由JBOSS提供的一个java开源框架.Netty提供异步的.事件驱动的网络应用程序框架和工具,用以快速 ...

  9. 读取PBOC电子现金指令流

    该指令流仅适用于T=0协议卡片.   终端对IC卡的响应: 60 须要额外的工作等待时间,说明IC卡端数据还未处理好. 61 发送GET RESPONSE命令取应答数据 6C 加上取字节数,命令重发 ...

  10. git ssh 22 端口不可用时通过https 443 端口配置git ssh

    Using SSH over the HTTPS port Sometimes, firewalls refuse to allow SSH connections entirely. If usin ...