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 ...
随机推荐
- WP8.1学习系列(第十七章)——Windows Phone重要图形、视觉指示器和通知
美感在手机应用中是不可或缺的,它是直观操作的代名词.在 Windows Phone 中,你的磁贴.初始屏幕.图标.控件和导航的视觉元素会引起用户对应用程序内的相关任务.优先事项或操作的注意,并采用新颖 ...
- JS插件---->SyntaxHighlighter的使用
SyntaxHighlighter是一款用于web页面的代码着色工具,可以用来着色多种语言.今天我们通过实例来学习一下它的用法.旧同桌不是老情人,但与你分享过的青春不比初恋少半分. SyntaxHig ...
- C++ 操作符new和delete
参考资料: http://en.cppreference.com/w/cpp/memory/new/operator_new http://en.cppreference.com/w/cpp/memo ...
- 重新签名IOS .ipa文件 (包含第三方框架和插件)
本文未经测试,初步看代码流程接近本人想法,留下作记录.Intoduction This code allow you to resign your own ipa assuming that you ...
- Clojure学习之比线性箭头操作
1. 单箭头( -> ) 单箭头操作符会把其参数form迭代式地依次插入到相邻的下个一个form中作为该form的第一个参数.这就好像把这些form串起来了,即线性化(Threading). 由 ...
- CentOS6 防火墙配置
清空现有的规则 iptables -F iptables -P INPUT DROP iptables -I INPUT -m state --state RELATED , ESTABLISHED ...
- Python3设置在shell脚本中自动补全功能的方法
本篇博客将会简短的介绍,如何在ubuntu中设置python自动补全功能. 需求:由于python中的内建函数较多,我们在百纳乘时,可能记不清函数的名字,同时自动补全功能,加快了我们开发的效率. 方法 ...
- ipv4组播预留地址
列表如下: 224.0.0.0 基准地址(保留) 224.0.0.1 所有主机的地址 224.0.0.2 所有组播路由器的地址 224.0.0.3 不分配 224.0.0.4 dvmrp 路由器 22 ...
- Web前端编码规范[转]
先插入一条广告,博主新开了一家淘宝店,经营自己纯手工做的发饰,新店开业,只为信誉!需要的亲们可以光顾一下!谢谢大家的支持!店名: 小鱼尼莫手工饰品店经营: 发饰.头花.发夹.耳环等(手工制作)网店: ...
- PHP 使用header函数设置HTTP头的示例方法 表头 (xlsx下载)
转载 http://justcoding.iteye.com/blog/601117/ //定义编码header( 'Content-Type:text/html;charset=utf-8 '); ...