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 ...
随机推荐
- 一些常用的字符串hash函数
unsigned int RSHash(const std::string& str) { unsigned int b = 378551; unsigned int a = 63689; u ...
- keep alive的相关介绍
无论Windows还是linux,Keepalive就三个配置参数.下文以linux环境为介绍. Technorati 标签: keepalive tcp_sock结构体中有三个有关的 ...
- 使用ResultSet,写了一个通用的查询方法
此方法很烂,以后优化 /** * 通用的查询方法:SELECT */ @SuppressWarnings({ "unchecked", "rawtypes" } ...
- VHDL基本常识
std_logic_vector和integer需要通过signed或unsigned进行间接转换(强制转换) a_std <= std_logic_vector(to_unsigned(a_i ...
- linux编程:环境表
每个进程在启动的时候都会收到一张环境表.环境表是由一个字符指针数组组成,每个指针包含一个以NULL结束的字符串的地址,全局变量environ包含了指针数组的地址: extern char **envi ...
- jquery.min.map详见
温故而知新,翻出来阮前辈的文章记录一下 日期:2013年1月23日 上周,jQuery 1.9发布. 这是2.0版之前的最后一个新版本,有很多新功能,其中一个就是支持Source Map. 访问 ht ...
- Android Material Design:滑动指示选项卡android.support.design.widget.TabLayout的简单使用
该TabLayout的功用,简单的说,就是当用户在该TabLayout的选项卡子item中选择触摸时候,文字和下方的指示器横条滑动指示.这个功能就是以前APP开发常用的选项卡某一卡片被切换.选中时候的 ...
- openerp - asterisk connector(转载)
原文:http://www.akretion.com/open-source-contributions/openerp-asterisk-voip-connector OpenERP - Aster ...
- 用Tupper自我指涉公式造图
塔珀自指公式是杰夫·塔珀(Jeff Tupper)发现的自指公式:此公式的二维图像与公式本身外观一样.此公式在众多数学与计算机科学课程里被用作绘制公式图像的练习作业. 公式最初于他2001年SIGGR ...
- html css布局
这几天有点急于求成了,原来每一门技术都像大海,只有深入其中才发现它比看到的更要深广的多. 虽然忙里偷闲的看了HTML5,NODE.JS,JAVASCRIPT核心等许多东西,但是真正掌握的不足十分之一, ...