hdu - 1072 Nightmare(bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1072
遇到Bomb-Reset-Equipment的时候除了时间恢复之外,必须把这个点做标记不能再走,不然可能造成死循环,也得不到最优解。
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
struct point
{
int x,y,time,step;
};
point s;
int n,m;
int maze[][];
int dir[][]={{-,},{,},{,},{,-}}; void bfs()
{
queue<point>que;
que.push(s);
maze[s.x][s.y]=;
while(!que.empty())
{
point t=que.front(); que.pop();
// printf("%d %d %d %d\n",t.x,t.y,t.step,t.time);
if(maze[t.x][t.y]==&&t.time>) {printf("%d\n",t.step);return;}
if(t.time==) continue;
for(int i=;i<;i++)
{
s.x=t.x+dir[i][],s.y=t.y+dir[i][];
if(s.x>=&&s.x<n&&s.y>=&&s.y<m&&maze[s.x][s.y]!=)
{
if(maze[s.x][s.y]==)
{
s.time=;
maze[s.x][s.y]=;
}
else s.time=t.time-;
s.step=t.step+;
que.push(s);
}
}
}
printf("-1\n");
}
int main()
{
//freopen("a.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
for(int j=;j<m;j++)
{
scanf("%d",&maze[i][j]);
if(maze[i][j]==)
{
s.x=i;
s.y=j;
s.step=;s.time=;
}
}
bfs();
}
return ;
}
hdu - 1072 Nightmare(bfs)的更多相关文章
- hdu 1072 Nightmare (bfs+优先队列)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1072 Description Ignatius had a nightmare last night. H ...
- HDU 1072 Nightmare
Description Ignatius had a nightmare last night. He found himself in a labyrinth with a time bomb on ...
- HDU 1072 Nightmare (广搜)
题目链接 Problem Description Ignatius had a nightmare last night. He found himself in a labyrinth with a ...
- HDU 1072 Nightmare 题解
Nightmare Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ)
HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- [hdu P3085] Nightmare Ⅱ
[hdu P3085] Nightmare Ⅱ Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU - 3085 Nightmare Ⅱ
HDU - 3085 Nightmare Ⅱ 双向BFS,建立两个队列,让男孩女孩一起走 鬼的位置用曼哈顿距离判断一下,如果该位置与鬼的曼哈顿距离小于等于当前轮数的两倍,则已经被鬼覆盖 #includ ...
- HDU 1072(记忆化BFS)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1072 题目大意:走迷宫.走到装置点重置时间,到达任一点时的时间不能为0,可以走重复路,求出迷宫最短时 ...
- hdu 1072(BFS) 有炸弹
http://acm.hdu.edu.cn/showproblem.php?pid=1072 题目大意是在一个n×m的地图上,0表示墙,1表示空地,2表示人,3表示目的地,4表示有定时炸弹重启器. 定 ...
随机推荐
- [BZOJ1009][HNOI2008]GT考试 DP+矩阵快速幂+KMP
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1009 我们令$dp(i,j)$表示已经填了$i$位,而且后缀与不幸运数字匹配了$j$位,那 ...
- shiro 通过jdbc连接数据库
本文介绍shiro通过jdbc连接数据库,连接池采用阿里巴巴的druid的连接池 参考文档:https://www.w3cschool.cn/shiro/xgj31if4.html https://w ...
- R in action读书笔记(10)-第八章:回归-- 异常观测值 改进措施
8.4 异常观测值 8.4.1 离群点 car包也提供了一种离群点的统计检验方法.outlierTest()函数可以求得最大标准化残差绝对值Bonferroni调整后的p值: > library ...
- Node.js——开放静态资源原生写法
借助了mime第三方包,根据请求地址请求的文件后缀,设置content-type
- Debug:This kind of launch is configured to openthe debug perspective when it解决办法
http://blog.sina.com.cn/s/blog_7ca3aa020100zlha.html 启动tomcat时,myeclipse报错: This kind of launch is c ...
- 网页显示403. That’s an error的解决方法。
使用Go*gent打开网页,经常出现403. That’s an error.下面是解决的方法. 方法/步骤 一.打开Go*gent的文件目录.不知道找文件目录的,可以在桌面上右键点击Go*g ...
- 指定PHP编码
有时候我们写好的PHP页面在网页中打开是乱码的,就需要指定编码,即加入代码: header("content-type:text/html;charset=utf-8"); 位置图 ...
- 五、面向切面的spring(1)
spring的依赖注入看完了,接下来是spring中与DI一并重要的AOP了,开始吧,GO. 在软件开发中,散布于应用中多处的功能被称为横切发关注点,通常来讲,这些横切关注点从概念上市与应用的业务逻辑 ...
- ionic提供的配色方案
.light #ffffff .stable #f8f8f8 .positive #387ef5 .calm #11c1f3 .balanced #33cd5f .energized #ffc900 ...
- CSU1007: 矩形着色
Description Danni想为屏幕上的一个矩形着色,但是她想到了一个问题.当点击鼠标以后电脑是如何判断填充的区域呢? 现在给你一个平面直角坐标系,其中有一个矩形和一个点,矩形的四条边均是平行于 ...