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 ...
随机推荐
- 济南学习 Day 2 T3 pm
它[问题描述]N个人坐成一圈,其中第K个人拿着一个球.每次每个人会以一定的概率向左边的人和右边的人传球.当所有人都拿到过球之后,最后一个拿到球的人即为胜者.求第N个人获胜的概率. (所有人按照编号逆时 ...
- 几道hihocoder不会做的题
1.https://hihocoder.com/problemset/problem/1433?sid=970287 boarding passes,不会做,看的别人的代码,现在还不是很理解. 2. ...
- WEB-INF简介
WEB-INF简介 WEB-INF是Java的WEB应用的安全目录.所谓安全就是客户端无法访问,只有服务端可以访问的目录. 如果想在页面中直接访问其中的文件,必须通过web.xml文件对要访问的文件进 ...
- 【风马一族_Android】 图能
---------------------------------- 第一次 名称:相片查看器 ---------------------------------- 通过3D.自动播放幻灯片.旋转.跳 ...
- HTML5-Geolocation&地图.html
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 分享:linux下apache服务器的配置和管理
linux下apache服务器的配置和管理. 一.两个重要目录: Apache有两个重要的目录:1.配置目录/etc/httpd/conf:2.文档目录/var/www: 二.两种配置模式: Apac ...
- How to disable Passwords must meet complexity requirements[windows 7]
The Password complexity is a Local Policy setting named "Passwords must meet complexity require ...
- openerp经典收藏 对象的预定义方法(转载)
对象的预定义方法 原文:http://shine-it.net/index.php/topic,2159.15.html 每个OpenERP的对象都有一些预定义方法,这些方法定义在基类osv.osv中 ...
- eclipse 安装插件不生效
操作: 下载了一个插件,插件中只有一个jar包,解压放到plugins目录,插件没生效. 解决方法: 把jar包直接扔到dropins目录下,并且删除eclipse\configuration\org ...
- WPF 实现QQ抖动
//wpf中实现类似于qq的抖动窗效果 //前段页面 <Window x:Class="WpfApplication4.MainWindow" xmlns="htt ...