[poj] Dungeon Master bfs
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! 三维的bfs, 总共可以向6个方向走,走一步步数+1, 可以按行读取地图, 把z轴设为最高维度, 基本过程和二维的bfs类似
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <queue>
using namespace std; char maze[][][];
bool v[][][];
int l, r, c; int dir[][] = {{,,},{-,,},{,,},{,-,},{,,},{,,-}}; struct node
{
int x, y, z, t;
}now, Next;
int bx, by, bz;
int ex, ey, ez; int bfs()
{
now.x = bx;
now.y = by;
now.z = bz;
now.t = ;
v[bz][bx][by] = ;
queue<node> q;
q.push(now);
while (!q.empty()) {
now = q.front();
q.pop();
if (now.z == ez && now.x == ex && now.y == ey)
return now.t;
for (int i = ; i < ; i++) {
Next.z = now.z + dir[i][];
Next.x = now.x + dir[i][];
Next.y = now.y + dir[i][];
Next.t = now.t + ;
if (Next.x>=&&Next.x<r&&Next.y>=&&Next.y<c&&Next.z>=&&Next.z<l
&& !v[Next.z][Next.x][Next.y] && maze[Next.z][Next.x][Next.y] != '#')
{
q.push(Next);
v[Next.z][Next.x][Next.y] = ;
}
}
}
return ;
} int main()
{
//freopen("1.txt", "r", stdin);
while (~scanf("%d%d%d", &l, &r, &c)) {
if (l+c+r == ) break;
memset(v, , sizeof(v));
for (int i = ; i < l; i++)
for (int j = ; j < r; j++)
scanf("%s", maze[i][j]); for (int i = ; i < l; i++)
for (int j = ; j < r; j++)
for (int k = ; k < c; k++) {
if (maze[i][j][k] == 'S') {
bz = i; bx = j; by = k;
}
if (maze[i][j][k] == 'E') {
ez = i; ex = j; ey = k;
} }
int ans = bfs();
if (ans == )
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n", ans);
} return ;
}
[poj] Dungeon Master bfs的更多相关文章
- POJ:Dungeon Master(三维bfs模板题)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16748 Accepted: 6522 D ...
- POJ2251 Dungeon Master —— BFS
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- hdu 2251 Dungeon Master bfs
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17555 Accepted: 6835 D ...
- poj 2251 Dungeon Master( bfs )
题目:http://poj.org/problem?id=2251 简单三维 bfs不解释, 1A, 上代码 #include <iostream> #include<cst ...
- 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 难度:0
http://poj.org/problem?id=2251 bfs,把两维换成三维,但是30*30*30=9e3的空间时间复杂度仍然足以承受 #include <cstdio> #inc ...
- POJ 2251 Dungeon Master (BFS最短路)
三维空间里BFS最短路 #include <iostream> #include <cstdio> #include <cstring> #include < ...
- Dungeon Master bfs
time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u POJ 2251 Descriptio ...
- POJ2251 Dungeon Master(bfs)
题目链接. 题目大意: 三维迷宫,搜索从s到e的最小步骤数. 分析: #include <iostream> #include <cstdio> #include <cs ...
随机推荐
- spring 获取bean的几种方式
1.读取xml文件的方式,这种在初学入门的时候比较适用 . ApplicationContext applicationContext = new ClassPathXmlApplicationCon ...
- 采集练习(十) php 获得电视节目预告---数据来自搜视网
前几天逛湖南卫视,偶然间发现它的网站上也有节目预告,一看源码,居然是来自搜视网的xml,于是就想获得它的数据(页面直接ajax加载估计会有跨域问题) 前阵子也写过另一个方法获得 节目预告(采集练习(七 ...
- history显示历史操作记录,并显示操作时间
在查看历史的操作记录有两种方式1.在用户的目录下的.bash_history文件中[root@node1 ~]# vi ~/.bash_history rebootvi /etc/sysconfig/ ...
- POJ - 2031 Building a Space Station 【PRIME】
题目链接 http://poj.org/problem?id=2031 题意 给出N个球形的 个体 如果 两个个体 相互接触 或者 包含 那么 这两个个体之间就能够互相通达 现在给出若干个这样的个体 ...
- c# wpf ComboBox 动态下拉框 及 动态默认值设定
1.下拉框声明 <ComboBox x:Name="DirComboBox" Width="150" Height="18" Marg ...
- POJ 1330 Nearest Common Ancestors 【最近公共祖先LCA算法+Tarjan离线算法】
Nearest Common Ancestors Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20715 Accept ...
- BZOJ 1637 [Usaco2007 Mar]Balanced Lineup:前缀和 + 差分
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1637 题意: Farmer John 决定给他的奶牛们照一张合影,他让 N (1 ≤ N ...
- 语义分割(semantic segmentation) 常用神经网络介绍对比-FCN SegNet U-net DeconvNet,语义分割,简单来说就是给定一张图片,对图片中的每一个像素点进行分类;目标检测只有两类,目标和非目标,就是在一张图片中找到并用box标注出所有的目标.
from:https://blog.csdn.net/u012931582/article/details/70314859 2017年04月21日 14:54:10 阅读数:4369 前言 在这里, ...
- Jexus是一款Linux平台上的高性能WEB服务器和负载均衡网关
什么是Jexus Jexus是一款Linux平台上的高性能WEB服务器和负载均衡网关,以支持ASP.NET.ASP.NET CORE.PHP为特色,同时具备反向代理.入侵检测等重要功能.可以这样说,J ...
- [转]深入了解 CSS3 新特性
简介 CSS 即层叠样式表(Cascading Stylesheet).Web 开发中采用 CSS 技术,可以有效地控制页面的布局.字体.颜色.背景和其它效果.只需要一些简单的修改,就可以改变网页的外 ...