原题链接

思路:bfs搜一发

AC代码:

 #include "map"
#include "queue"
#include "math.h"
#include "stdio.h"
#include "string.h"
#include "iostream"
#include "algorithm"
#define abs(x) x > 0 ? x : -x
#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b using namespace std; int di[][] = {{,,},{,,},{,,-},{,-,},{,,},{-,,}};
int Map[][][];
bool vis[][][];
int t; struct Node
{
int zz,xx,yy;
int step;
}; void Bfs()
{
memset(vis,,sizeof(vis));
queue<Node>Q;
Node now,next;
int l,r; now.zz=;
now.xx=;
now.yy=;
now.step=;
vis[][][] = ; Q.push(now); while(!Q.empty())
{
now = Q.front();
Q.pop(); if(Map[now.zz][now.xx][now.yy]==)
{
if(now.step<=t)
printf("YES\n");
else
printf("NO\n");
return;
}
if(Map[now.zz][now.xx][now.yy]==)
l=,r=;
if(Map[now.zz][now.xx][now.yy]==)
l=,r=; for(int i=l; i<r; i++)
{
next.zz = now.zz + di[i][];
next.xx = now.xx + di[i][];
next.yy = now.yy + di[i][];
next.step = now.step + ;
if(i==||i==)
next.step = now.step; if(Map[next.zz][next.xx][next.yy]!=)
{
if(!vis[next.zz][next.xx][next.yy])
{
vis[next.zz][next.xx][next.yy] = ;
Q.push(next);
}
}
}
}
printf("NO\n");
} int main()
{
int c,n,m,i,j,k;
char s;
scanf("%d",&c);
while(c--)
{
memset(Map,,sizeof(Map));
scanf("%d%d%d",&n,&m,&t);
for(i=; i<=; i++)
{
for(j=; j<=n; j++)
{
getchar();
for(k=; k<=m; k++)
{
scanf("%c",&s);
if(s=='S'||s=='.')
Map[i][j][k] = ;
if(s=='P')
Map[i][j][k] = ;
if(s=='#')
Map[i][j][k] = ;
if(s=='*')
Map[i][j][k] = ;
}
}
getchar();
} Bfs();
}
return ;
}

hdu 2102 BFS的更多相关文章

  1. [hdu 2102]bfs+注意INF

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 感觉这个题非常水,结果一直WA,最后发现居然是0x3f3f3f3f不够大导致的……把INF改成I ...

  2. hdu 4531 bfs(略难)

    题目链接:点我 第一次不太清楚怎么判重,现在懂了,等下次再做 /* *HDU 4531 *BFS *注意判重 */ #include <stdio.h> #include <stri ...

  3. hdu - 2102 A计划 (简单bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目还是不难,注意起点一定是(0,0,0),然后到达P点时间<=t都可以. 用一个3维字符数组存储图 ...

  4. hdu 2102 A计划(双层BFS)(具体解释)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...

  5. HDU 2102 A计划(BFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目大意:公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输 ...

  6. HDU 2102 A计划(两层地图加时间限制加传送门的bfs)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Time Limit: 3000/1000 MS (Java/Others)    Me ...

  7. HDU - 2102 A计划 【BFS】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 思路 题目有两个坑点 0.Output 说 能在T时刻 找到公主 就输出 YES 但实际上 只要 ...

  8. hdu 2102 A计划 具体题解 (BFS+优先队列)

    题目链接:pid=2102">http://acm.hdu.edu.cn/showproblem.php?pid=2102 这道题属于BFS+优先队列 開始看到四分之中的一个的AC率感 ...

  9. hdu 2102 A计划-bfs

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

随机推荐

  1. 关于ICE

    转自:http://wenda.chinabaike.com/b/38322/2013/1103/614756.html 一.ICE产生的背景 基于信令协议的多媒体传输是一个两段式传输.首先,通过信令 ...

  2. VisualStudio一打开工程就崩溃-重打开output显示We were unable to automatically populate your Visual Studio Online accounts.

    and this method exactly effected on me

  3. 用ajax和js怎么做出滚动条滚到最下面分页

    获取滚动条位置(scrollTop) 获取可视窗口高度(viewportHeight) 获取整个页面可滚动高度(scrollHeight) 当scrollTop+viewportHeight==scr ...

  4. CSS3动画属性animation的用法

    转载: 赞生博客 高端订制web开发工作组 » CSS3动画属性animation的用法 CSS3提供了一个令人心动的动画属性:animation,尽管利用animation做出来的动画没有flash ...

  5. 使用J2SE API读取Properties文件的六种方法

    1.使用java.util.Properties类的load()方法示例: InputStream in = lnew BufferedInputStream(new FileInputStream( ...

  6. Css3 提示框

    <div class="arrow_box"><span>xxy is a so cool boy</span></div> css ...

  7. Uva 839 Not so Mobile

    0.最后输出的yes no的大小写 1.注意 递归边界   一直到没有左右子树 即b1=b2=false的时候 才返回 是否 天平平衡. 2.注意重量是利用引用来传递的 #include <io ...

  8. mac OS X操作 -- 常用

    显示/隐藏默认隐藏文件:defaults write com.apple.finder AppleShowAllFiles -bool true/false 重置ROOT密码: http://www. ...

  9. jdbc 各驱动写法

    1.Oracle8/8i/9i数据库(thin模式) Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); ...

  10. 循环遍历泛型集合List绑定到table

    <%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false&quo ...