ZOJ 1940 Dungeon Master 三维BFS
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Is an escape possible? If yes, how long will it take?
Input
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
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 <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100001
const int inf=0x7fffffff; //无限大 int dx[] = {,,-,,,};
int dy[] = {,,,,,-};
int dz[] = {,-,,,,}; char Map[][][];
int vis[][][], L, R, C; struct node
{
int x, y, z;
int time;
}st, ed;
queue<node> q; bool check(int x, int y, int z)
{
if(x >= && x <= L && y >= && y <= R && z >= && z <= C)
return true;
return false;
} int BFS()
{
int x, y, z, t, i;
while(!q.empty())
{
node tmp = q.front();
q.pop();
x = tmp.x;
y = tmp.y;
z = tmp.z;
t = tmp.time;
for(i = ; i < ; i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
int nz = z + dz[i];
if(!vis[nx][ny][nz] && Map[nx][ny][nz] != '#' && check(nx,ny,nz))
{
if(nx == ed.x && ny == ed.y && nz == ed.z)
return t+;
vis[nx][ny][nz] = ;
node temp;
temp.x = nx;
temp.y = ny;
temp.z = nz;
temp.time = t + ;
q.push(temp);
}
}
}
return -;
} int main()
{
while(~scanf("%d%d%d",&L, &R, &C) && (L + R + C))
{
memset(vis,,sizeof(vis));
int i, j, k;
for(i = ; i <= L; i++)
{
for(j = ; j <= R; j++)
{
for(k = ; k <= C; k++)
{ cin>>Map[i][j][k];
if(Map[i][j][k] == 'S')
{
st.x = i, st.y = j, st.z = k;st.time = ;
q.push(st);
vis[i][j][k] = ;
}
else if(Map[i][j][k] == 'E')
ed.x = i, ed.y = j, ed.z = k;
}
}
}
int ans = BFS();
if(ans == -)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n",ans);
while(!q.empty()) q.pop();
}
return ;
}
ZOJ 1940 Dungeon Master 三维BFS的更多相关文章
- POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)
POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ:Dungeon Master(三维bfs模板题)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16748 Accepted: 6522 D ...
- ZOJ 1940 Dungeon Master【三维BFS】
<题目链接> 题目大意: 在一个立体迷宫中,问你从起点走到终点的最少步数. 解题分析: 与普通的BFS基本类似,只需要给数组多加一维,并且走的时候多加 上.下这两个方向就行. #inclu ...
- Dungeon Master(三维bfs)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- UVa532 Dungeon Master 三维迷宫
学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时) #i ...
- 【POJ - 2251】Dungeon Master (bfs+优先队列)
Dungeon Master Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...
- 棋盘问题(DFS)& Dungeon Master (BFS)
1棋盘问题 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的 ...
随机推荐
- word文档下划线无法显示的解决方法
在编辑文档的时候经常会遇到下划线无法显示的情况,如图: 如果遇到不能在姓名后面加下划线的情况,我们该怎么做? 请看下面的图解: 1.首先点击左上角的office图标 2.点击右下角“word选项” 3 ...
- RobotFramework基本用法(二)
双击打开C:\Python27\Scripts目录下的 ride.py 一,定义变量,打印 1,右键File-->New Poreject,在项目下右键New suite,在套件下右键 New ...
- 洛谷P3811乘法逆元
传送门 线性递推 #include <iostream> #include <cstdio> #include <cstring> #include <alg ...
- 80端口被System占用 造成Apache不能启动的解方案
运行netstat -aon | findstr :80 ,发现pid是4的进程占用着80端口,这还是一个系统进程,kill不掉.所以只能另想办法: 1.打开注册表:regedit 2.找到:HKEY ...
- SQL Server 管理常用的SQL和T-SQL
1. 查看数据库的版本 select @@version 常见的几种SQL SERVER打补丁后的版本号: 8.00.194 Microsoft SQL Server 2000 8.00.384 Mi ...
- Effective STL 学习笔记 32 ~ 33
Effective STL 学习笔记 32 ~ 33 */--> div.org-src-container { font-size: 85%; font-family: monospace; ...
- Linux 相关
一.WCHAN的含义 WCHAN 进程正在睡眠的内核函数名称:该函数的名称是从/root/system.map文件中获得的. 参考:解析ANDROID ps命令执行后各项参数的含义 二.查看线程 ps ...
- HBase 入门笔记-数据落地篇
一.前言 关于数据落地方面,HBase官网也有相关介绍.本文主要介绍一下实际工作中涉及的数据存储方面的一些经验和技巧,主要涉及表rowkey设计.数据落地方案 二.表设计 相对于MySQL等关系型数据 ...
- CVE-2012-4969
Microsoft Internet Explorer ‘CMshtmlEd::Exec’函数释放后使用漏洞(CNNVD-201209-394) Microsoft Internet Explorer ...
- 一步一步学习IdentityServer4 (2) 开始一个简单的事例
前面将来一些配置,但是很多都不是必要的,先放一些事例需要的简要配置把 既然是IdentityServer4 所里下面的例子我 直接放到 Linux上 测试环境 CentOS 7 +Nginx1.9.3 ...