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 ...
随机推荐
- [Whole Web] [Node.js, PM2] Controlling runaway apps using pm2
shows how to enable features in your pm2 config file that allow you to prevent runaway apps from bri ...
- Linux下安装ACE
ACE 5.6下载地址:http://download.dre.vanderbilt.edu/ 方法一: 1. 解开ACE-install.sh文件 tar –zxvf ACE-5.6.ta ...
- Cocos-2d 坐标系及其坐标转换
Cocos-2d中,涉及到4种坐标系: GL坐标系Cocos2D以OpenglES为图形库,所以它使用OpenglES坐标系.GL坐标系原点在屏幕左下角,x轴向右,y轴向上. 屏幕坐标系苹果的Quar ...
- Java基础知识强化之IO流笔记48:IO流练习之 复制单级文件夹案例
1. 复制单级文件夹 数据源:e:\\demo 目的地:e:\\test 分析: A:封装目录 B:获取该目录下的所有文本的File数组 C:遍历该File数组,得到每一个File对象 ...
- 爬虫神器XPath,程序员带你免费获取周星驰等明星热门电影
本教程由"做全栈攻城狮"原创首发,本人大学生一枚平时还需要上课,但尽量每日更新文章教程.一方面把我所习得的知识分享出来,希望能对初学者有所帮助.另一方面总结自己所学,以备以后查看. ...
- "ORA-00054: 资源正忙, 但指定以 NOWAIT 方式获取资源, 或者超时失效"的快速解决方法
引自:http://hi.baidu.com/fynaa/item/c2978952d8d542dfd48bacf6 讲了一大堆: 综合下: 解决方案:select session_id from v ...
- (转) ASP.NET页面缓存
原文:http://www.cnblogs.com/Sky_KWolf/archive/2010/12/05/1897158.html 静态页面全部内容保存在服务器内存中.当再有请求时,系统将缓存中的 ...
- ACM——圆柱体的表面积
lems 1092 圆柱体的表面积 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:2697 测试通过:414 ...
- Struts2 多文件下载
Step1:导入支持jar包 commons-fileupload-1.3.1.jar commons-io-2.4.jar jstl-1.2.jar standard-1.1.2.jar commo ...
- mediawiki数据库的下载地址及导入方法
mediawiki导入数据库 数据库下载:http://zh.wikipedia.org/wiki/Wikipedia:%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%8B%E8% ...