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个棋子的所有可行的 ...
随机推荐
- ETL利器Kettle实战应用解析系列三
本系列文章主要索引如下: 一.ETL利器Kettle实战应用解析系列一[Kettle使用介绍] 二.ETL利器Kettle实战应用解析系列二 [应用场景和实战DEMO下载] 三.ETL利器Kettle ...
- Scrapy:创建爬虫程序的方式
Windows 10家庭中文版,Python 3.6.4,Scrapy 1.5.0, 在Scrapy中,建立爬虫程序或项目的方式有两种(在孤读过Scrapy的大部分文档后): 1.继承官方Spider ...
- python 写入execl记录
记录代码中关于写execl的操作 # 创建execl workbook = xlwt.Workbook(encoding='utf8') # 创建样式实例 style = xlwt.XFStyle() ...
- bootstrap-fileinput上传文件的插件使用总结----编辑已成功上传过的图片
http://plugins.krajee.com/file-plugin-methods-demo 具体操作 http://plugins.krajee.com/file-preview-manag ...
- 洛谷P1177快速排序
传送门 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...
- Centos之文件搜索命令locate
locate命令 locate 文件名 在后台数据库中按文件名搜索,搜索速度更快 /var/lib/mlocate #locate命令所搜索的后台数据库 updatedb 更新数据库 locate搜索 ...
- Linux学习笔记:pwd与dirs的区别
在Linux中可以使用pwd和dirs进行当前目录查看,分别用于显示当前目录和显示完整目录记录.具体如下: 1.pwd 显示当前目录 2.dirs 显示目录堆叠中的记录 END 2018-08-21 ...
- nsis安装包_示例脚本语法解析
以下是代码及解析,其中有底色的部分为脚本内容. 注释.!define.变量.!include.常量 ; Script generated by the HM NIS Edit Script Wizar ...
- C#socket编程序(一)
在讲socket编程之前,我们先看一下最常用的一些类和方法,相信这些能让你事半功倍. 一.IP地址操作类 1.IPaddress类 a.在该类中有一个 parse()方法,能够把点分十进制IP地址 转 ...
- 何时调用getView?——从源码的角度给出解答
先来看ListView类中的makeAndAddView方法: 没有数据变化:从mRecycler中取得可视的view 数据有变化:obtainView /** * 获取视图填充到列表的item中去, ...