题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102

感觉这个题非常水,结果一直WA,最后发现居然是0x3f3f3f3f不够大导致的……把INF改成INF+INF就过了。

#include<bits/stdc++.h>
using namespace std; bool vis[][][];
char s[][][];
const int INF=0x3f3f3f3f; const int fx[]={,,,-};
const int fy[]={,-,,}; int bfs()
{
memset(vis,false,sizeof(vis));
queue< pair<int,int> > q;
while (!q.empty()) q.pop();
q.push(make_pair(*+*+,));
vis[][][]=true;
while (!q.empty())
{
int layer=q.front().first/;
int x=q.front().first%/;
int y=q.front().first%;
int st=q.front().second;
q.pop();
for (int i=;i<;i++)
{
int xx=x+fx[i];
int yy=y+fy[i];
if (s[layer][xx][yy]!='*' && !vis[layer][xx][yy])
{
if (s[layer][xx][yy]=='P' || (s[layer][xx][yy]=='#' && s[layer^][xx][yy]=='P')) return st+;
if (s[layer][xx][yy]=='#' && !vis[layer^][xx][yy])
{
vis[layer][xx][yy]=vis[layer^][xx][yy]=true;
q.push(make_pair((layer^)*+xx*+yy,st+));
}
if (s[layer][xx][yy]=='.' || s[layer][xx][yy]=='S')
{
vis[layer][xx][yy]=true;
q.push(make_pair(layer*+xx*+yy,st+));
}
}
}
}
return INF+INF;
} int main()
{
int T;
scanf("%d",&T);
while (T--)
{
memset(s,'*',sizeof(s));
int n,m,t;
cin >>n >>m >>t;
for (int _=;_<;_++)
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
cin >>s[_][i][j];
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
if (s[][i][j]=='#'&&s[][i][j]=='#' || s[][i][j]=='#'&&s[][i][j]=='*' || s[][i][j]=='*'&&s[][i][j]=='#') s[][i][j]=s[][i][j]='*';
if (bfs()<=t) cout <<"YES" <<endl;
else cout <<"NO" <<endl;
}
return ;
}

[hdu 2102]bfs+注意INF的更多相关文章

  1. hdu 2102 BFS

    原题链接 思路:bfs搜一发 AC代码: #include "map" #include "queue" #include "math.h" ...

  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.Output 说 能在T时刻 找到公主 就输出 YES 但实际上 只要 ...

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

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

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

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

  6. HDU 2102 A计划(BFS)

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

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

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

  8. HDU 2102 A计划 (BFS)

    A计划 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

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

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

随机推荐

  1. Django admin操作

      无名小妖     昵称:无名小妖园龄:1年6个月粉丝:22关注:1 +加关注 搜索     常用链接 我的随笔 我的评论 我的参与 最新评论 我的标签 我的标签 Python(1) python3 ...

  2. git使用ssh密钥(转)

    git使用https协议,每次pull, push都要输入密码,相当的烦.使用git协议,然后使用ssh密钥.这样可以省去每次都输密码. 大概需要三个步骤:一.本地生成密钥对:二.设置github上的 ...

  3. laravel5.5jwt-auth的使用

    laravel5.5 + jwt-auth:dev-develop 安装扩展 composer require tymon/jwt-auth:dev-develop --prefer-source 添 ...

  4. spring boot 中文文档地址

    spring boot 中文文档地址     http://oopsguy.com/documents/springboot-docs/1.5.4/index.html Spring Boot 参考指 ...

  5. JMeter Plugins Manager

    JMeter插件管理器官网: https://jmeter-plugins.org/ 把jmeter-plugins-manager-0.16.jar放到C:\JMeter\apache-jmeter ...

  6. 【LoadRunner】解决LR11无法录制Chrome浏览器脚本问题

    LoadRunner录制脚本时,遇到高版本的IE.FireFox,或者Chrome浏览器,会出现无法录制脚本的问题,下面就来讲一下如何利用LR自带的wplus_init_wsock.exe插件进行脚本 ...

  7. Django数据模型--字段详解

    一.字段 1.CharField: 字段数据类型为字符串 class Test(models.Model): test = models.CharField(max_length=) 2.Intege ...

  8. linux下 su 与 su - 的区别和使用

    Linux下su与su -命令的区别   在启动服务器ntpd服务时遇到一个问题 使用 su root 切换到root用户后,不可以使用service命令: 使用 su - 后,就可以使用servic ...

  9. 在Code::Blocks中编译和使用wxWidgets3.0.0教程

      跳转至:指南,搜索 注意,编译Code :: Blocks的对wxWidgets的3.0.0链接不是很稳定,但该库至少可以被正确编译,(只是使用的时候可能会有问题):CodeBlocks开发商都在 ...

  10. 剑指offer-数值的整数次方12

    class Solution: def Power(self, base, exponent): # write code here if base==0: return 0 if exponent= ...