原题链接

思路: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. long和int的区别

    转自:http://blog.sina.com.cn/s/blog_6f62c9510101svjz.html 突然间就想到了long和int到底什么区别(发现有很多问题都是突然间想到的),然后百度. ...

  2. vim用法小节

    1.把一个文件的内容全选复制到另一个文件 方案一: gg"*yG 然后另外一个vim "*p "*是系统剪贴板寄存器 方案二: 打开另一个文件,然后输入 :r filen ...

  3. linux command file/type which/whereis

    今天遇到几个命令,初见时感觉好像啊,不太能区分其具体功能和区别,因此特来记录一下. 1. file和type file: 查看文件类型 type: display information of com ...

  4. codeforce ABBYY Cup 3.0 - Finals (online version) B2. Shave Beaver! 线段树

    B2. Shave Beaver!   The Smart Beaver has recently designed and built an innovative nanotechnologic a ...

  5. HDU 5900 QSC and Master 区间DP

    QSC and Master Problem Description   Every school has some legends, Northeastern University is the s ...

  6. loj 1379(最短路变形)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27087 思路:题目的意思是求S->T的所有路径中花费总和小于 ...

  7. win10无法枚举容器中的对象 访问被拒绝

    http://jingyan.baidu.com/article/48a42057cd0bc0a924250419.html

  8. 【File】递归删除文件夹中子级文件/夹,并删除文件夹

    今天有这样一个需求,需要删除某一个文件夹,但是文件夹中还有子级的文件 或者还可能会有文件夹在里面,所以就需要使用一个简单的递归才能将文件夹删除成功,包括文件夹中的子级文件/夹.!!! 其实很简单,就一 ...

  9. 深入理解KMP算法

    前言:本人最近在看<大话数据结构>字符串模式匹配算法的内容,但是看得很迷糊,这本书中这块的内容感觉基本是严蔚敏<数据结构>的一个翻版,此书中给出的代码实现确实非常精炼,但是个人 ...

  10. Maven 项目导入错误解决。

    Description Resource Path Location Type Failure to transfer org.apache.maven:maven-core:jar:2.0.6 fr ...