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 ...
随机推荐
- [Javascript] The Array filter method
One very common operation in programming is to iterate through an Array's contents, apply a test fun ...
- PHP获取IP所在地区(转)
1.获取IP地址的API新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js新浪多地域测试方法:http:/ ...
- java19 先开服务器,再开客户端
先开服务器,再开客户端. import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOExcep ...
- string的操作
除了顺序容器共有的操作之外,string类型还提供了一些额外的操作.这些操作中的大部分要么是提供string类和C风格字符数组之间的相互转换,要么是增加了允许我们用下标代替迭代器的版本. 构造stri ...
- schedule() 和 scheduleAtFixedRate() 的区别--转载
1. schedule() ,2个参数方法:在执行任务时,如果指定的计划执行时间scheduledExecutionTime <= systemCurrentTime,则task会被立即执行. ...
- secureCRT常用设置
一.快捷键: 1. ctrl + a : 移动光标到行首[常用] 2. ctrl + e :移动光标到行尾[常用] 3. ctrl + d :删除光标之后的一个字符 4. ctrl + w : 删除行 ...
- 图解如何用U盘重装系统
第一类方法: 原生U盘安装,本工具制作完的U盘启动菜单含Windows7操作系统安装功能,使用本功能可以将Win7系统完美移植到你的U盘中.本功能不用进PE不用虚拟光驱,不受FAT32和NTFS文件系 ...
- Android主题换肤 无缝切换
2016年7月6日 更新:主题换肤库子项目地址:ThemeSkinning,让app集成换肤更加容易.欢迎star以及使用,提供改进意见. 更新日志: v1.3.0:增加一键切换切换字体(初版)v1. ...
- yii中的自定义组件
yii中的自定义组件(组件就是一些自定义的公用类) 1.在项目目录中的protected/components/Xxxx.php 2.在Xxxx.php中定义一个类,类名必须与文件名相同 3.控制器中 ...
- java 用eclipse j2ee写的servlet 程序,WEB-INF下的配置文件web.xml在哪啊?谢谢!
我用的版本是tomcat7.0,在webcontent\web-inf里只有一个空文件夹lib,写完servlet 类程序,就可以运行了,我想知道自动生成的配置文件在哪里?或者说从哪里能够看出来配置内 ...