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表示有定时炸弹重启器. 定 ...
随机推荐
- 死磕 java集合之LinkedList源码分析
问题 (1)LinkedList只是一个List吗? (2)LinkedList还有其它什么特性吗? (3)LinkedList为啥经常拿出来跟ArrayList比较? (4)我为什么把LinkedL ...
- 一个简单的Java代码生成工具—根据数据源自动生成bean、dao、mapper.xml、service、serviceImpl
目录结构 核心思想 通过properties文件获取数据源—>获取数据表的字段名称.字段类型等—>生成相应的bean实体类(po.model).dao接口(基本的增删改查).mapper. ...
- core\stm32f10x.h(244): error: #67: expected a "}"
- 【数据分析 R语言实战】学习笔记 第三章 数据预处理 (下)
3.3缺失值处理 R中缺失值以NA表示,判断数据是否存在缺失值的函数有两个,最基本的函数是is.na()它可以应用于向量.数据框等多种对象,返回逻辑值. > attach(data) The f ...
- 镜像中的 Everything, GnomeLive ,KdeLive ,livecd ,NetInstall的区别?
everything: 对完整版安装盘的软件进行补充,集成所有软件 GnomeLive , GNOME桌面版 KdeLive , KDE桌面版 livecd 光盘上运行的系统 ,NetInstall ...
- asterisk-java ami4 一些基本功能的例子
比如:挂机,拨号,拨外线,保留通话,示闲,示忙等等.... 在api中可以获得这些方法说明 /** * 给分机挂机 * @param Extension 要挂机的分机号 * @return * ...
- 洛谷P2863 [USACO06JAN]牛的舞会The Cow Prom
代码是粘的,庆幸我还能看懂. #include<iostream> #include<cstdio> #include<cmath> #include<alg ...
- codevs 1082 线段树练习 3 --分块练习
时间限制: 3 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区间[a,b]的所有数增加X 2:询问区间[ ...
- 迅为IMX6Q四核核心板商业级|工业级|IMX6Plus版本|IMX6DL双核核心板
IMX6Q处理器:兼容单核,双核,工业级,汽车级,IMX6Q最新Plus版本,共用同一底板,高端产品无忧. i.MX6系列针对消费电子.工业控制和汽车应用领域,它将ARM Cortex-A9架构的高功 ...
- Python3.0 调用HTMLTestRunner生成的报告中不能显示用例中print函数的输出
官方原生的HTMLTestRunner.py支持python2.0版本,python3.0版本的使用需要做一些修改: Python3调用HTMLTestRunner执行用例生成测试报告中,不能正常显示 ...