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( ...
随机推荐
- 深入理解计算机中的 csapp.h和csapp.c
csapp.h其实就是一堆头文件的打包,在http://csapp.cs.cmu.edu/public/code.html 这里可以下载.这是<深入理解计算机系统>配套网站. 在头文件的# ...
- C语言判断文件是否存在(转)
int access(const char *filename, int amode); amode参数为0时表示检查文件的存在性,如果文件存在,返回0,不存在,返回-1. 这个函 ...
- 数据分析(3):ufunc
universal function 可以对数组里的每一个元素进行操作,底层是C语言实现的,在对数组运算时表现卓越 1.1 初步上手 x = np.linspace(0,2*np.pi,10) y = ...
- js String对象
字符串(String) 字符串(String)使用长度属性length来计算字符串的长度: 在字符串中查找字符串 字符串使用 indexOf() 来定位字符串中某一个指定的字符首次出现的位置: 实例 ...
- 手机页面的meta标签
<meta charset="utf-8"/><meta name="viewport" content="width=device ...
- PHP之echo/print
1.PHP中有两个基本的输出方式:echo和print: 2.echo和print的区别: **echo:可以输出一个或多个字符串: **print:只允许输出一个字符串,返回值总为1: 3.echo ...
- css布局1
body <body> <header id='title'> <h1>Holla</h1> </header> <div id='c ...
- zoj 3469 Food Delivery 区间dp + 提前计算费用
Time Limit: 2 Seconds Memory Limit: 65536 KB When we are focusing on solving problems, we usual ...
- 实现窗体随着鼠标移动(控件)--《用delphi开发共享软件》-15.1任务管理器
private //窗体移动: OldPos,NewPos:TPoint; bMove:Boolean; procedure TForm1.FormMouseDown(Sender: TObject; ...
- docker push到本地仓库失败
开启registry的方法: docker run -d -p : -v /data/registry:/tmp/registry registry 出错内容: Error: Status tryin ...