题目: 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的更多相关文章

  1. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  2. POJ 2251 Dungeon Master (三维BFS)

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  3. poj 2251 Dungeon Master 3维bfs(水水)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21230   Accepted: 8261 D ...

  4. POJ 2251 Dungeon Master(三维空间bfs)

    题意:三维空间求最短路,可前后左右上下移动. 分析:开三维数组即可. #include<cstdio> #include<cstring> #include<queue& ...

  5. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  6. BFS POJ 2251 Dungeon Master

    题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...

  7. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

  8. 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 ...

  9. POJ 2251 Dungeon Master (非三维bfs)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 55224   Accepted: 20493 ...

随机推荐

  1. Win7 64bit 安装VisualSVN出现报错:Servic 'VisualSVN Server' failed to start.解决办法

    问题描述: Win7 64bit 安装VisualSVN时出现报错: Servic 'VisualSVN Server' failed to start.Please check VisualSVN ...

  2. Apache Mina 2.x 框架+源码分析

    源码下载 http://www.apache.org/dyn/closer.cgi/mina/mina/2.0.9/apache-mina-2.0.9-src.tar.gz 整体架构 核心过程(IoA ...

  3. 遍历map的四方方法

    public static void main(String[] args) { Map<String, String> map = new HashMap<String, Stri ...

  4. JSON返回的自定义

    当返回json格式的数据时,不想自己组织结果集,可以利用类的call方法. json类: <?php class Json { private $_data; public function _ ...

  5. 【转】GitHub删除一个仓库——2013-08-27 21

    http://xiacijian.blog.163.com/blog/static/849931902012111195041170/ 1.进入要删除的仓库 2.找到 导航栏 Code  NetWor ...

  6. 从cmd中进入MySQL的命令界面

    两种方式进入mysql命令界面 第一.直接开始界面→搜索mysql客户端登陆界面 第二.从cmd中进入MySQL的命令界面 2010-05-17 10:02:05|  分类: mysql|字号 订阅 ...

  7. Windows下安装破解JIRA6.3.6

    相关工具下载地址:http://pan.baidu.com/s/1kT9xZEJ 安装环境: WindowsXP MySQL-5.5.28 JDK1.6.0_21 JIRA功能全面,界面友好,安装简单 ...

  8. CentOS 6.6 yum源完全配置

    原文地址 http://blog.csdn.net/halazi100/article/details/41311837 一 yum 简介 yum,是"Yellow dog Updater, ...

  9. Unity3D 之UGUI 面板

    UGUI中使用面板,可以对一组控件分为一个组. 一个面板里面可以添加一些控件,就如同Html中的<div>一样.

  10. MongoDB 2.6.x 的安装部署

    1. 下载mongodb 2.6.x版本的zip包,在D盘创建目录MongoDB,解压缩到D:\MongoDB目录. 创建数据库目录D:\MongoDB\data,接下来打开命令行窗口,切换到D:\M ...