题意:在一个地图里逃亡,2是起点,3是终点,1是路,0是墙,逃亡者携带一个炸弹,6分钟就会炸,要在6分钟前到达4可以重制时间,问是否能逃亡,若能则输出最小值

我的思路:bfs在5步内是否存在3,存在则输出退出。记录到达每一点剩余时间,如果再次到达某点的剩余时间大于原剩余时间则更新,加入队列。

 #include <iostream>
#include <cstring>
#include <queue> using namespace std;
const int M = ;
int map[M][M];
int graph[M][M];
struct node
{
int x,y;
int step;
int time;
}; node now,nn,next1;
queue <struct node> q;
int n,m;
int dire[][] = {{-,},{,-},{,},{,}}; int bfs()
{
while (!q.empty())
{
now = q.front();
q.pop();
for (int i = ;i < ;i++)
{
int x = now.x + dire[i][];
int y = now.y + dire[i][];
if (x>= && x<n && y>= && y<m && map[x][y] != && map[x][y]!= && now.time->) //踩点到到达4也会爆炸
{
next1.x = x;
next1.y = y;
if (map[x][y] == )
{
return now.step+;
}
if (map[x][y] == )
{
next1.time = ;
}
else next1.time = now.time - ;
next1.step = now.step+;
if (next1.time > graph[x][y]) //加入队列条件
{
graph[x][y] = next1.time;
q.push(next1);
}
}
}
}
return -;
}
int main()
{
int t;
cin >> t;
while (t--)
{
cin >> n >> m;
while (!q.empty())
q.pop();
for (int i = ;i < n;i++)
{
for (int j = ;j < m;j++)
{
cin >> map[i][j];
graph[i][j] = ;
if (map[i][j] == )
{
nn.x = i;
nn.y = j;
nn.step = ;
nn.time = ;
q.push(nn);
}
}
}
cout << bfs() << endl;
}
return ;
}

hdoj1072 Nightmare bfs的更多相关文章

  1. hdoj1072 Nightmare(bfs)

    题目大意: 在迷宫中有一个炸弹,过六个单位时间就会爆炸,要你求一个起点到迷宫的终点的最短距离,迷宫中有时间重置器,当你走到这个格子,炸弹的爆炸时间重新置为0,迷宫中标识为墙壁的格子不能走,到达任意一个 ...

  2. hdu 1072 Nightmare (bfs+优先队列)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1072 Description Ignatius had a nightmare last night. H ...

  3. HDUOJ-----(1072)Nightmare(bfs)

    Nightmare Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  4. Nightmare BFS

    Ignatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. The la ...

  5. hdu - 1072 Nightmare(bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1072 遇到Bomb-Reset-Equipment的时候除了时间恢复之外,必须把这个点做标记不能再走,不然可能造 ...

  6. HDU 3085 Nightmare Ⅱ (双向BFS)

    Nightmare Ⅱ Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  7. nyoj 483 Nightmare【bfs+优先队列】

    Nightmare 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 Ignatius had a nightmare last night. He found him ...

  8. HDU-1072 Nightmare (bfs+贪心)

    Nightmare Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Sub ...

  9. Nightmare Ⅱ HDU - 3085 (双向bfs)

    Last night, little erriyue had a horrible nightmare. He dreamed that he and his girl friend were tra ...

随机推荐

  1. 使用AIR进行移动APP开发常见功能和问题(上)

    1.  获取最近联系人 思路:侦听Geolocation的update事件,获取经度和纬度信息,再把坐标信息上传至服务器,服务器比较坐标信息算出距离,返回最近位置的若干个人. update时间在2种情 ...

  2. 如何使用矩阵乘法加速动态规划——以[SDOI2009]HH去散步为例

    对这个题目的最初理解 开始看到这个题,觉得很水,直接写了一个最简单地动态规划,就是定义 f[i][j]为到了i节点路径长度为j的路径总数, 转移的话使用Floyd算法的思想去转移,借助这个题目也理解了 ...

  3. Android 隐藏软键盘

    隐藏软键盘 public void hideSoftInputView() { InputMethodManager manager = ((InputMethodManager) this.getS ...

  4. MyEclipse-Initializing Java Tooling问题

    问题描述: 今天早上打开Eclipse,打开Package Explorer 中项目时,总出现卡死现象. MyEclipse状态栏显示两个任务,(1) Checking for Updates (2) ...

  5. javascript this的一些误解

    太拘泥于"this"的字面意思就会产生一些误解.有两种常见的对于this 的解释,但是它们都是错误的. 1.指向自身 人们很容易把this 理解成指向函数自身,这个推断从英语的语法 ...

  6. 网络请求 ---iOS

    //1.url要访问的资源 NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"]; //2.请求,要向服务器请求 N ...

  7. link js重构心得

    过年前后一段时间,对link库的代码进行的大量的重构,代码精简了许多,性能也得到了很大的改善,写此文记录期间所做的改进和重构,希望对看到此文的js程序员有所帮助. 1. 代码构建 最初代码使用gulp ...

  8. windows下搭建Nexus3私服和基于IDEA15的Maven学习笔记

    搭建Nexus私服. 首先去官网下载window下用的zip文件.https://www.sonatype.com/download-oss-sonatype. 解压之后包含下面两个文件 进入nexu ...

  9. [.NET] RabbitMQ 的行为艺术

    RabbitMQ 的行为艺术 序 好像,今天已经是 2 月 28 号了. 听说,29.30.31 号放假. 据说,有图,有真相. 目录 简介 环境搭建 示例一:简单的 Hello World 示例二: ...

  10. 打造“黑客“手机--Kali Nethunter

    从三月份开始,继续更新技术文章.一个月没有更新技术文章了,这一个月有一部分时间是在休息,另一部分时间是在学习汇编和操作系统,沉淀底层和逆向方面的技术. 今年年初,为了玩一下 kali NetHunte ...