题意:给出一个三维坐标的牢,给出起点st,给出终点en,问能够在多少秒内逃出。

学习的第一题三维的广搜@_@

过程和二维的一样,只是搜索方向可以有6个方向(x,y,z的正半轴,负半轴)

另外这一题的输入的方式还要再多看看--@_@--

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define maxn 55
using namespace std;
int map[maxn][maxn][maxn],vis[maxn][maxn][maxn];
int dir[6][3]={{0,0,1},{0,0,-1},{1,0,0},{-1,0,0},{0,1,0},{0,-1,0}};
int l,r,c,flag;
char str[10005];
struct node
{
int x,y,z;
int step;
} st,en;
queue<node> q;
void bfs(int x,int y,int z)
{
node now,next;
while(!q.empty()) q.pop();//调用前清空队列
now.x=x;now.y=y;now.z=z;now.step=0;
q.push(now);
vis[x][y][z]=1;
while(!q.empty())
{
now=q.front();q.pop();
for(int i=0;i<6;i++)
{
next.x=now.x+dir[i][0];
next.y=now.y+dir[i][1];
next.z=now.z+dir[i][2];
if(map[next.x][next.y][next.z]&&!vis[next.x][next.y][next.z])
{
vis[next.x][next.y][next.z]=1;
next.step=now.step+1;//步数加1之后再如队列,因为 搞反 这个wa了好几次
q.push(next);
if(next.x==en.x&&next.y==en.y&&next.z==en.z)
{
flag=1;
en.step=next.step;
return;
}
}
}
}
return;
}
int main()
{
char ch;
int i,j,k;
while(scanf("%d %d %d",&l,&r,&c)!=EOF&&l&&r&&c)
{
flag=0;
memset(map,0,sizeof(map));
memset(vis,0,sizeof(vis)); gets(str);
for(i=1;i<=l;i++)
{
for(j=1;j<=r;j++)
{
for(k=1;k<=c;k++)
{
scanf("%c",&ch);
if(ch=='S') {st.x=i;st.y=j;st.z=k;}
if(ch=='E'){en.x=i;en.y=j;en.z=k;}
if(ch!='#') map[i][j][k]=1;//map数组 相当于限定是否出界
}
gets(str);
}
gets(str);
}
bfs(st.x,st.y,st.z);
if(flag) printf("Escaped in %d minute(s).\n",en.step);
else printf("Trapped!\n");
}
}

  go---go-----===

POJ 2251 Dungeon Master【BFS】的更多相关文章

  1. POJ - 2251 Dungeon Master 【BFS】

    题目链接 http://poj.org/problem?id=2251 题意 给出一个三维地图 给出一个起点 和 一个终点 '#' 表示 墙 走不通 '.' 表示 路 可以走通 求 从起点到终点的 最 ...

  2. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  3. POJ 2251 Dungeon Master (三维BFS)

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  4. POJ 2251 Dungeon Master【三维BFS模板】

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...

  5. poj 2251 Dungeon Master(bfs)

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...

  6. (简单) POJ 2251 Dungeon Master,BFS。

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...

  7. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  8. BFS POJ 2251 Dungeon Master

    题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...

  9. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

随机推荐

  1. DICOM医学图像处理:fo-dicom网络传输之 C-Echo and C-Store

    背景: 上一篇博文对DICOM中的网络传输进行了介绍.主要參照DCMTK Wiki中的英文原文.通过对照DCMTK与fo-dicom两个开源库对DICOM标准的详细实现,对理解DICOM标准有一个更直 ...

  2. Medium上的文章

    Welcome to Medium, a place to read, write, and interact with the stories that matter most to you. 网站 ...

  3. CreateProcess

    #include <Windows.h> //WINBASEAPI //BOOL //WINAPI //CreateProcessW( //_In_opt_ LPCWSTR lpAppli ...

  4. MySQL用户添加和分配权限

    mysql数据库insertdelete服务器file mysql> grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口 ...

  5. LCD段码驱动

    假如要第3个数码关显示“8.”,则3A-3D均得为1,即Seg3和Seg4均得为1.假设模具Seg和驱动芯片Seg对应,则只需往HT1621的地址Seg3和Seg4分半发送0xF. 注意:HT1621 ...

  6. LAMP 建立 Wordpress 站点 Linux Apache MariaDB PHP

    使用LAMP建立Wordpress, 要求如下: 准备工作: VMware 14 CentOS 7.4 最小化 安装镜像 Wordpress 安装包,  下载 预热: 使用VMware新建4台虚拟机, ...

  7. laravel 5.5 项目报错

    报错内容: ErrorException (E_WARNING) Declaration of App\Observers\SiteObserver::updated($site) should be ...

  8. 被我忽略许久的set

    心塞,set一直是我忽略的一个数据结构 1.生成一个set: 1) set(iterable) 传入一个可以迭代的数据结构: eg:字符串;元组;列表,字典 2) {v1,v2,.......,vn} ...

  9. 拉格朗日插值&&快速插值

    拉格朗日插值 插值真惨 众所周知$k+1$个点可以确定一个$k$次多项式,那么插值就是通过点值还原多项式的过程. 设给出的$k+1$个点分别是$(x_0,y_0),(x_1,y_1),...,(x_k ...

  10. php>$_SERVER服务的一些常用命令

    $_SERVER['REMOTE_ADDR'] //当前用户 IP . $_SERVER['REMOTE_HOST'] //当前用户主机名   $_SERVER['REQUEST_URI'] //UR ...