POJ 2251 Dungeon Master(广搜,三维,简单)
简单的3d广搜,做法类似与 hdu 的 胜利大逃亡
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
#define MAXN 32
char map[MAXN][MAXN][MAXN];
int a,b,c;
bool vis[MAXN][MAXN][MAXN];
struct tt
{
int x,y,z,step;
};
queue<tt>q;
int xx[]={,,,-,,};
int yy[]={,-,,,,};
int zz[]={,,,,,-};
int bfs(int sx,int sy,int sz,int ex,int ey,int ez)
{
if(a==&&b==&&c==)return ;
while(!q.empty())
q.pop();
memset(vis,false,sizeof(vis));
tt front,rear,temp;
front.x=sx;front.y=sy;front.z=sz;front.step=;
q.push(front);
vis[sx][sy][sz]=true;
while(!q.empty())
{
temp=q.front();
q.pop();
if(temp.x==ex&&temp.y==ey&&temp.z==ez)
return temp.step;//原来是这个放错地方了,应该对出栈的数据进行检验
for(int i=;i<;i++)
{
rear.x=temp.x+xx[i];
rear.y=temp.y+yy[i];
rear.z=temp.z+zz[i];
rear.step=temp.step+;
if(rear.x>=&&rear.x<a&&rear.y>=&&rear.y<b&&rear.z>=&&rear.z<c&&map[rear.x][rear.y][rear.z]!='#'&&vis[rear.x][rear.y][rear.z]==false)
{
q.push(rear);
vis[rear.x][rear.y][rear.z]=true;
}
}
}
return ;
} int main()
{
int i,j,k,ans,ex,ey,ez,sx,sy,sz;
while(scanf("%d%d%d",&a,&b,&c)!=EOF)
{
if(a==&&b==&&c==)break;
for(i=;i<a;i++)
{
for(j=;j<b;j++)
{
scanf("%s",map[i][j]);
for(k=;k<c;k++)
{
if(map[i][j][k]=='S')
sx=i,sy=j,sz=k;
if(map[i][j][k]=='E')
ex=i,ey=j,ez=k;
}
}
}
ans=bfs(sx,sy,sz,ex,ey,ez);
if(ans==)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n",ans);
}
return ;
}
POJ 2251 Dungeon Master(广搜,三维,简单)的更多相关文章
- POJ 2251 Dungeon Master (非三维bfs)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55224 Accepted: 20493 ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- 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 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- 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
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- POJ 2251 Dungeon Master【三维BFS模板】
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...
随机推荐
- Windows phone 中一些实用的控件
一.TextBlock:这个控件其实就是Label控件. <TextBlock x:Name="PageTitle" Text="page name" M ...
- arduino入门学习实现语音控制LED灯
需要的准备的硬件arduino+PC+麦克风实现语音命令控制LED灯的亮灭. 首先需要将写好的arduino程序烧录到arduino uno主板中,下面是代码如下: int val;//定义变量val ...
- WPF 类型“System.ComponentModel.ISupportInitialize”在未被引用的程序集中定义。
问题:类型“System.ComponentModel.ISupportInitialize”在未被引用的程序集中定义.必须添加对程序集“System, Version=4.0.0.0, Cultur ...
- C#各种常用开源框架-支持开源!分享!
下面罗列了开发及学习过程中所涉及的开源类库的列表! AForge.NET Accord.NET NAudio nVLC Speex C# WebServer FFmpeg FFmpeg.NET Flo ...
- Mongodb Java Driver 参数配置解析
要正确使用Mongodb Java Driver,MongoClientOptions参数配置对数据库访问的并发性能影响极大. connectionsPerHost:与目标数据库能够建立的最大conn ...
- 给view 添加事件
//绑定图片点击事件 UITapGestureRecognizer *g=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@select ...
- Json(2)-DataContractJsonSerializer
public static void DataContractSerializeDemo() { User user = new User { UserID = 1 ...
- Eclipse 下 opennms 开发环境搭建
1.eclipse3.5或更高版本,并且使用纯净的java版.下载地址:Eclipse for Java Developers. 2.安装需要的插件.通过Help/Install New Softwa ...
- UIActivityIndicatorView的使用
class ViewController: UIViewController,UIActionSheetDelegate{ @IBOutlet weak var label1: UILabel! @I ...
- 微软职位内部推荐-Senior SDE for Big Data
微软近期Open的职位: Title: Senior SDE The Big Data Tooling team looking for a talented and passionate devel ...