B - Dungeon Master

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

Submit Status

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!

BFS水题,套模板按6个方向拓展就行了。

 #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <string.h>
using namespace std;
int to[][] = {{,,},{,,-},{,,},{,-,},{,,},{-,,}};
char s[][][];
int maps[][][];
int x1,y1,z1;
int x2,y2,z2;
int L,R,C;
struct data
{
int x;
int y;
int z;
int step;
};
int check(int x,int y,int z)
{
if(x< || y< || z< || x>=L || y>=R || z>=C)
return ;
else if(s[x][y][z] == '#')
return ;
else if(maps[x][y][z])
return ;
return ;
}
int bfs()
{
queue<data> q;
data now,nex;
now.x=x1;
now.y=y1;
now.z=z1;
now.step=;
maps[x1][y1][z1]=;
q.push(now);
while(!q.empty())
{
now=q.front();
q.pop();
if(now.x==x2&&now.y==y2&&now.z==z2)
{
return now.step;
}
for(int i=;i<;i++)
{ nex=now;
nex.x=now.x+to[i][];
nex.y=now.y+to[i][];
nex.z=now.z+to[i][];
if(check(nex.x,nex.y,nex.z))
{
continue;
}
maps[nex.x][nex.y][nex.z]=;
nex.step=now.step+;
q.push(nex);
}
}
return ;
}
int main()
{
while(scanf("%d%d%d",&L,&R,&C),L+R+C)
{
cin>>R>>C;
int i,j,k;
for(i=;i<L;i++) //
{
for(j=;j<R;j++)
{
scanf("%s",s[i][j]);
for(k=;k<C;k++)
{
if(s[i][j][k]=='S')
{
x1=i;
y1=j;
z1=k;
}
else if(s[i][j][k]=='E')
{
x2=i;
y2=j;
z2=k;
}
}
}
}
memset(maps,,sizeof(maps));
int ans;
ans=bfs();
if(ans)
{printf("Escaped in %d minute(s).\n",ans);}
else
{
printf("Trapped!\n");
}
}
return ;
}

BFS POJ2251 Dungeon Master的更多相关文章

  1. POJ2251 Dungeon Master —— BFS

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

  2. POJ-2251 Dungeon Master (BFS模板题)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  3. POJ2251 Dungeon Master(bfs)

    题目链接. 题目大意: 三维迷宫,搜索从s到e的最小步骤数. 分析: #include <iostream> #include <cstdio> #include <cs ...

  4. POJ2251——Dungeon Master(三维BFS)

    和迷宫问题区别不大,相比于POJ1321的棋盘问题,这里的BFS是三维的,即从4个方向变为6个方向. 用上队列的进出操作较为轻松. #include<iostream> #include& ...

  5. bfs—Dungeon Master—poj2251

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32228   Accepted: 12378 ...

  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. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

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

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

  9. POJ 2251 Dungeon Master (非三维bfs)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 55224   Accepted: 20493 ...

随机推荐

  1. Kafka Consumer

    Push VS Pull An initial question we considered is whether consumers should pull data from brokers or ...

  2. HDU 2296 Ring [AC自动机 DP 打印方案]

    Ring Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissio ...

  3. Linux下jdk环境配置

    1.下载jdk http://www.oracle.com/technetwork/java/javase/downloads/index.html 我选择64位的版本 jdk-8u121-linux ...

  4. [Python Study Notes]CS架构远程访问获取信息--SERVER端v2.0

    更新内容: 1.增加内存信息获取 2.增加电池信息获取 3.增加磁盘信息获取 4.重新布局窗体 5.增加窗体名称 6.增加连接成功之前,不可按压 ''''''''''''''''''''''''''' ...

  5. PLEC-交流电机系统+笔记

    1.固有机械特性近似图 2.三相交流电机的控制系统 1)理论推导 第一次制动选择能耗制动,第二次制动选择倒拉制动. 2)模型搭建 3)模拟仿真 3.心得体会和笔记总结 制动方式的选择主要是根据各个制动 ...

  6. android应用中去android市场去评分的功能实现(吐槽一波个人应用上线...)

    一般的app可能会有这中功能,在应用中去android商店评分来提高排名,前段时间也把我的博客园上传到商店,这里不得不吐槽一些android商店的开放平台. 酷派,vivo,oppo,联想不支持个人开 ...

  7. 二、Item Pipeline和Spider-----基于scrapy取校花网的信息

    Item Pipeline 当Item在Spider中被收集之后,它将会被传递到Item Pipeline,这些Item Pipeline组件按定义的顺序处理Item. 每个Item Pipeline ...

  8. ubuntu下boost编译安装

    ubuntu下boost编译安装 boost 安装 1.依赖安装 apt-get install mpi-default-dev libicu-dev python-dev python3-dev l ...

  9. 韩信点兵(hanxin)

    相传韩信才智过人,从不直接清点自己军队的人数,只要让士兵先后以三人一排.五人一排.七人一排地变换队形,而他每次只掠一眼队伍的排尾就知道总人数了.输入包含多组数据,每组数据包含3个非负整数a,b,c,表 ...

  10. java中的Collection集合类

    随着1998年JDK 1.2的发布,同时新增了常用的Collections集合类,包含了Collection和Map接口.而Dictionary类是在1996年JDK 1.0发布时就已经有了.它们都可 ...