POJ:Dungeon Master(三维bfs模板题)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 16748 | Accepted: 6522 |
Description
Is an escape possible? If yes, how long will it take?
Input
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!
题解:
就是很裸的模板题,细心就好。其中'S'是起点,‘E’是终点,‘#’不能走。
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
char map[][][];
int fx[]= {,-,,,,};
int fy[]= {,,,-,,};
int fz[]= {,,,,,-};
struct node
{
int ans;
int x,y,z;
};
struct node t,f;
int v[][][];
int n,m,k;
void bfs(int xx,int yy,int zz)
{
memset(v,,sizeof(v));
queue<node>q;
t.x=xx;
t.y=yy;
t.z=zz;
t.ans=;
q.push(t);
v[t.x][t.y][t.z]=;
while(!q.empty())
{
t=q.front();
q.pop();
if(map[t.x][t.y][t.z]=='E')
{
printf("Escaped in %d minute(s).\n",t.ans);
return ;
}
for(int i=; i<; i++)
{
f.x=t.x+fx[i];
f.y=t.y+fy[i];
f.z=t.z+fz[i];
if(f.x>=&&f.x<n&&f.y>=&&f.y<m&&f.z>=&&f.z<k&&v[f.x][f.y][f.z]==&&map[f.x][f.y][f.z]!='#')
{
v[f.x][f.y][f.z]=;
f.ans=t.ans+;
q.push(f);
}
}
}
printf("Trapped!\n");
return ;
}
int main()
{
int xx,yy,zz;
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
if(n==&&m==&&k==) break;
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
scanf("%*c%s",map[i][j]);
}
}
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
for(int z1=; z1<k; z1++)
{
if(map[i][j][z1]=='S')
{
xx=i;
yy=j;
zz=z1;
break;
}
}
}
}
bfs(xx,yy,zz);
}
return ;
}
POJ:Dungeon Master(三维bfs模板题)的更多相关文章
- 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 ...
- 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 ...
- ZOJ 1940 Dungeon Master 三维BFS
Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Desc ...
- Dungeon Master(三维bfs)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- POJ 2251 Dungeon Master【三维BFS模板】
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...
- 【POJ - 2251】Dungeon Master (bfs+优先队列)
Dungeon Master Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...
- POJ - 2251 Dungeon Master 【BFS】
题目链接 http://poj.org/problem?id=2251 题意 给出一个三维地图 给出一个起点 和 一个终点 '#' 表示 墙 走不通 '.' 表示 路 可以走通 求 从起点到终点的 最 ...
- POJ 2251 三维BFS(基础题)
Dungeon Master Description You are trapped in a 3D dungeon and need to find the quickest way out! Th ...
随机推荐
- JS案例 - 基于vue的移动端长按手势
================================惯例碎碎念前言================================ 当时首先想到要做长按事件的时候,我想到的是vue内部的自 ...
- Why is IMAP better than POP?
https://www.fastmail.com/help/technical/imapvspop.html POP is a very simple protocol that only allow ...
- Nginx写IO占用高故障处理
文章来源:<https://www.centos.bz/2015/04/handle-nginx-write-io-problem/> 故障现象 突然收到一台服务器负载过高告警,紧接着网站 ...
- 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验七:PS/2模块① — 键盘
实验七:PS/2模块① — 键盘 实验七依然也是熟烂的PS/2键盘.相较<建模篇>的PS/2键盘实验,实验七实除了实现基本的驱动以外,我们还要深入解PS/2时序,还有PS/2键盘的行为.不 ...
- 在openLdap上添加memberOf属性
我为openldap添加memberof属性的时候参考了这个文章:http://www.adimian.com/blog/2014/10/how-to-enable-memberof-using-op ...
- Unity3D 记第二次面试
2014-03-10 忍不住投递了几份简历大概有20个,总共收到面试电话2个,十分之一.一个是11号下午4点面试另一个是12号下午3点面试(后来没去至于原因下面有)12号没去,为什么?因为招聘要求“精 ...
- Node.js 文件系统fs模块
Node.js 文件系统封装在 fs 模块是中,它提供了文件的读取.写入.更名.删除.遍历目录.链接等POSIX 文件系统操作. 与其他模块不同的是,fs 模块中所有的操作都提供了异步的和 同步的两个 ...
- CentOS 6.8下Apache绑定多个域名的方法
如何通过设置Apache的http.conf文件,进行多个域名的绑定(假设我们要绑定的域名是discuz11.com和discuz22.com,独立IP为25.25.25.25). 域名/IP地址 域 ...
- Bagging和Boosting的概念与区别
随机森林属于集成学习(ensemble learning)中的bagging算法,在集成算法中主要分为bagging算法与boosting算法, Bagging算法(套袋发) bagging的算法过程 ...
- markdown公式编辑参考
原文作者,https://www.cnblogs.com/q735613050/p/7253073.html