hdu 2102 BFS
思路: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的更多相关文章
- [hdu 2102]bfs+注意INF
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 感觉这个题非常水,结果一直WA,最后发现居然是0x3f3f3f3f不够大导致的……把INF改成I ...
- hdu 4531 bfs(略难)
题目链接:点我 第一次不太清楚怎么判重,现在懂了,等下次再做 /* *HDU 4531 *BFS *注意判重 */ #include <stdio.h> #include <stri ...
- hdu - 2102 A计划 (简单bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目还是不难,注意起点一定是(0,0,0),然后到达P点时间<=t都可以. 用一个3维字符数组存储图 ...
- hdu 2102 A计划(双层BFS)(具体解释)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...
- HDU 2102 A计划(BFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目大意:公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输 ...
- HDU 2102 A计划(两层地图加时间限制加传送门的bfs)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Time Limit: 3000/1000 MS (Java/Others) Me ...
- HDU - 2102 A计划 【BFS】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 思路 题目有两个坑点 0.Output 说 能在T时刻 找到公主 就输出 YES 但实际上 只要 ...
- hdu 2102 A计划 具体题解 (BFS+优先队列)
题目链接:pid=2102">http://acm.hdu.edu.cn/showproblem.php?pid=2102 这道题属于BFS+优先队列 開始看到四分之中的一个的AC率感 ...
- hdu 2102 A计划-bfs
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
随机推荐
- 第十九篇:提高SOUI应用程序渲染性能的三种武器
SOUI是一套100%开源的基于DirectUI的客户端开发框架. 基于DirectUI设计的UI虽然UI呈现的效果可以很炫,但是相对于传统的win32应用程序中每个控件一个窗口句柄的形式,渲染效率是 ...
- FAST特征点检测
Features From Accelerated Segment Test 1. FAST算法原理 博客中已经介绍了很多图像特征检测算子,我们可以用LoG或者DoG检测图像中的Blobs(斑点检测) ...
- 遍历windows驱动
驱动都存在 \\Driver 或者 \\FileSystem 目录对象里 我们只需要遍历这两个目录就可以遍历windows所有驱动 知识点 \\Driver \\FileSystem (dt _OB ...
- C#写Windows Service(windows服务程序)
背景: 要学习使用一个新东西,我们必须知道他是个什么东西.对于我们此次研究的windows服务来说,他又是个什么东西,其实也没有什么高深的了. windows service概述: 一个 ...
- Linux sed 批量替换多个文件中的字符串
sed -i "s/oldstring/newstring/g" `grep oldstring -rl yourdir` 例如:替换/home下所有文件中的www.bcak.co ...
- AngularJS学习之Select(选择框)
1.AngularJS可以使用数组或对象创建一个下拉列表选项: 2.在AngularJS中我们可以使用ng-option指令创建一个下拉列表:列表项通过对象和数组循环输出: <div ng-ap ...
- JQuery学习之语法
1.JQuery语法就是通过选取HTML元素,并对选取的元素执行某些操作: 基础语法:$(selector).action() (1)美元符号定义jQuery (2)选择符(selector)查询和查 ...
- HTTP基础05--http首部
HTTP 报文首部 HTTP 请求报文 在请求中,HTTP 报文由方法.URI.HTTP 版本.HTTP 首部字段等部分构成. HTTP 响应报文 在响应中,HTTP 报文由 HTTP 版本.状态码( ...
- ccc 播放动画
cc.Class({ extends: cc.Component, properties: { anim:cc.Animation, }, // use this for initialization ...
- ACM: HDU 5285 wyh2000 and pupil-二分图判定
HDU 5285 wyh2000 and pupil Time Limit:1500MS Memory Limit:65536KB 64bit IO Format:%I64d &a ...