POJ 2252 Dungeon Master 三维水bfs
题目: http://poj.org/problem?id=2251
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std; char maze[][][];
bool vis[][][];
int dir[][] = {{,,}, {,,}, {,,}, {,,-}, {,-,}, {-,,}}; struct Point
{
int x, y, z, step;
}; struct Point start; queue<struct Point>q;
void bfs()
{
while(!q.empty())q.pop();
memset(vis, , sizeof(vis));
q.push(start);
vis[start.x][start.y][start.z] = ;
while(!q.empty())
{
struct Point u = q.front();
q.pop();
if(maze[u.x][u.y][u.z] == 'E')
{
printf("Escaped in %d minute(s).\n", u.step);
return;
}
for(int d = ; d < ; d++)
{
int nx = u.x + dir[d][];
int ny = u.y + dir[d][];
int nz = u.z + dir[d][];
if(maze[nx][ny][nz] != '#' && maze[nx][ny][nz] != && !vis[nx][ny][nz])
{
q.push((struct Point){nx, ny, nz, u.step+});
vis[nx][ny][nz] = ;
}
}
}
printf("Trapped!\n");
} int main()
{
int a, b, c;
while(scanf("%d %d %d", &a, &b, &c) != EOF)
{
if(a == && b == && c == )break;
memset(maze, , sizeof(maze));
for(int i = ; i <= a; i++)
{
for(int j = ; j <= b; j++)
{
scanf("%s", &maze[i][j][]);
for(int k = ; k <= c; k++)
{
if(maze[i][j][k] == 'S')
start = (struct Point){i, j, k, };
}
}
}
bfs();
}
return ;
}
POJ 2252 Dungeon Master 三维水bfs的更多相关文章
- 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 2251 Dungeon Master 3维bfs(水水)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21230 Accepted: 8261 D ...
- POJ 2251 Dungeon Master(三维空间bfs)
题意:三维空间求最短路,可前后左右上下移动. 分析:开三维数组即可. #include<cstdio> #include<cstring> #include<queue& ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
- 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)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55224 Accepted: 20493 ...
随机推荐
- [Canvas] Introduction to drawing with p5js
In this lesson we look at using color and the basic drawing methods of p5js, and how they can be com ...
- [HTTPS] MAN IN THE MIDDLE (MITM)
If you go a public caffee shop, they have free wifi. How could you make sure your infomration cannot ...
- 用USB安装Linux系统(centos7)
网上关于CentOS 7 的安装教程挺多的,但在前期的引导配置上很多都没有写清楚,让人很郁闷,以致于昨天安装的时候总是到不了安装界面.经过一番胡乱倒腾,终于找到了妥妥的解决方案(鸟哥的书功不可没啊^_ ...
- js广告浮动
一个广告框在指定区域,有定位属性的父级区域内,一直向右向左移动,如果碰到左右边框,反向,如果碰到上下边距,反向,实现在指定框中浮动的效果. <!doctype html> <html ...
- datejs lib
// Get today's date Date.today(); // Add 5 days to today Date.today().add(5).days(); // Get Friday o ...
- CSS的!important修改权重
!important语法和描述 !important为开发者提供了一个增加样式权重的方法.应当注意的是!important是对整条样式的声明,包括这个样式的属性和属性值. #example { fon ...
- WORDPRESS 后台500错误解决方法集合
引自: http://www.guuglc.com/565.html 这篇文章本质上我是不可能会写到,就因为7号那天晚上,我准备搬家的时候,发现前台完好,进入后台却500错误. 这时我就得急的,毕竟明 ...
- webresource.axd文件的配置及使用
今天看到同事的代码中使用到了webresource.axd,特地认真地看了一下它的使用.主要用途有两点: 1.当作httphandler用,但是比handler更好用一点,不需要考虑路径,用的时候,只 ...
- Spring中整合Titles
在<Spriing实战(第三版)>这本书中,有一个使用titles的例子,但是这是一个不完整的例子.那么要参照起来就比较难了,于是找到了下面这篇博客. 在Spring中使用tiles2 ( ...
- 12_复杂查询01_Mapper代理实现
[工程截图] [代码实现] [user.java] package com.Higgin.Mybatis.po; import java.util.Date; public class User { ...