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表示有定时炸弹重启器. 定 ...
随机推荐
- WAMP配置虚拟目录
1.启动wamp所有服务,输入localhost或localhost:端口号确保wamp环境正常无误. 2.设置httpd.conf 2.1打开文件:单击wamp在电脑右下角的图标=>wamp= ...
- js基础 -----鼠标事件(按下 拖拽)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Java语法基础-序列化
33. Java序列化中如果有些字段不想进行序列化,怎么办? 答:对于不想进行序列化的变量,使用transient关键字修饰. transient关键字的作用是:阻止实例中那些用此关键字修饰的的变量序 ...
- 【C++】朝花夕拾——STL vector
STL之vector篇 N久之前是拿C的数组实现过vector中的一些简单功能,什么深拷贝.增删查找之类的,以为vector的实现也就是这样了,现在想想真是...too young too naive ...
- python学习第三次
while循环 表示当条件成立的时候就循环适用于不知道具体循环次数,但是确定在某个条件成立的情况下就循环while语法:while 条件表达式:语句块#另一种表达方式while 条件表达式:语句块1e ...
- CAD参数绘制实心圆弧填充(com接口)
C#中实现代码说明: private void DrawPathToHatch1() { //把路径的开始位置移动指定的点 //参数一为点的X坐标 ,参数二为点的Y坐标,参数三为该点处开始宽度,对Po ...
- 【原】CentosDocker安装(一)
CentosDocker安装 来源:https://www.runoob.com/docker/centos-docker-install.html 1.前提条件 目前,CentOS 仅发行版本中的内 ...
- 使用HTML5+调用手机摄像头和相册
前言:前端时间使用HTML5做了一个WEB端APP,其中用到了H5页面调用手机摄像头的功能,当时也是花了不少时间去研究.最终是采用了HTML5plus(HTML5+)的方式完成了该功能,现将具体方法简 ...
- linux系统查看网络连接情况
netstat命令状态说明: CLOSED 没有使用这个套接字[netstat 无法显示closed状态] LISTEN 套接字正在监听连接[调用listen ...
- Python学习-初始列表
初始列表 列表中的排放是没有顺序的并且可以被修改 在列表中你可以放入任何的元素类型.字符串,数字,布尔值等等,甚至还可以进行列表的嵌套 列表的注意特征:用中括号包围,中间用逗号分隔开 list = [ ...