题意:给出一个三维坐标的牢,给出起点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. hdu 2079 选课时间(题目已改动,注意读题) (母函数)

    代码: #include<cstdio> #include<cstring> using namespace std; int main() { int t; scanf(&q ...

  2. [JZOJ 5852] [NOIP2018提高组模拟9.6] 相交 解题报告 (倍增+LCA)

    题目链接: http://172.16.0.132/senior/#main/show/5852 题目: 题目大意: 多组询问,每次询问树上两条链是否相交 题解: 两条链相交并且仅当某一条链的两个端点 ...

  3. [poj 3349] Snowflake Snow Snowflakes 解题报告 (hash表)

    题目链接:http://poj.org/problem?id=3349 Description You may have heard that no two snowflakes are alike. ...

  4. C++线程传参数

    struct TThreadParam { LPVOID pThis; int visionIndex; }; class CMilTestDlg : public CDialog { // Cons ...

  5. Nodemailer 报错

    { [Error: connect ECONNREFUSED] code: ‘ECONNREFUSED’, errno: ‘ECONNREFUSED’, syscall: ‘connect’ } 如果 ...

  6. SpringBoot(一) 基础入门

    SpringBoot简要 简化Spring应用开发的一个框架: 整个Spring技术栈的一个大整合: J2EE开发的一站式解决方案: 自动配置:针对很多Spring应用程序常见的应用功能,Spring ...

  7. SpringBoot学习笔记(14)----应用监控-HTTP方式

    SpringBoot提供了三种应用监控的方式 通过HTTP(最简单方便) 通过JMX 通过远程shell 这里就是用最简单的方式来使用SpringBoot的应用监控 首先引入依赖,pom文件如下 &l ...

  8. 【BZOJ1014】【JSOI2008】火星人prefix

    题意: Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 ...

  9. React显示文件夹中SVG

    import React from 'react'; import _ from 'lodash'; import styles from './iconPicker.less'; const req ...

  10. BZOJ 3790 神奇项链(回文自动机+线段树优化DP)

    我们预处理出来以i为结尾的最长回文后缀(回文自动机的构建过程中就可以求出)然后就是一个区间覆盖,因为我懒得写贪心,就写了线段树优化的DP. #include<iostream> #incl ...