题意:给出一个三维坐标的牢,给出起点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. bzoj5157: [Tjoi2014]上升子序列(树状数组LIS)

    5157: [Tjoi2014]上升子序列 题目:传送门 题解: 学一下nlogn的树状数组求最长上生子序列就ok(%爆大佬) 离散化之后,用一个数组记录一下,直接树状数组做 吐槽:妈耶...一开始不 ...

  2. ElasticSearch 深入理解 三:集群部署设计

    ElasticSearch 深入理解 三:集群部署设计 ElasticSearch从名字中也可以知道,它的Elastic跟Search是同等重要的,甚至以Elastic为主要导向. Elastic即可 ...

  3. 143.vector模板库

    myvector.h #pragma once #include <initializer_list> #include <iostream> using namespace ...

  4. jquery定时器

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  5. STM8S103之串口

    1.串口发送中断标志的清除,只能靠往UART_DR中写数据,这个的本质含义是,发送中断是指发送完成中断,所以往UART_DR中写数据可以清除发送中断标志.但是这样又会导致新写的数据完成后又会产生中断, ...

  6. ActiveMQ学习笔记(21)----ActiveMQ集成Tomcat

    1. 监控和管理Broker Web Console 方式:直接访问ActiveMQ的管理页面:http://localhost:8161/admin,默认的用户名和密码是admin/admin.具体 ...

  7. webpack 操作

    依赖安装 :  全局安装webpack : sudo npm install webpack -g 本地安装webpack : npm install webpack —save-dev  需要注意的 ...

  8. [洛谷P1835]素数密度

    题目大意:求区间[l,r]中素数的个数($1\leq l,r\le 2^{31}$,$r-l\leq 10^6$). 解题思路:首先,用筛法筛出$2~\sqrt{r}$内的素数. 然后用这些素数筛l~ ...

  9. [洛谷P1352][codevs1380]没有上司的舞会

    题目大意:某大学有N个职员,编号为1~N.他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.现在有个周年庆宴会,宴会每邀请来一个职员都会增加一定的快乐指数Ri,但如果某个职员的上司来参加舞 ...

  10. BZOJ 2938 [POI2000]病毒 (剪枝/A*迭代搜索)

    LOJ BZOJ 题目大意:给你一些模式串,问是否存在一个无限长的文本串,不包含任何一个给定的模式串 并没有想到去模拟合法的文本串在模式串的Trie图上匹配的过程..我好菜啊 如果一个字符串合法,那么 ...