题意:在一个地图里逃亡,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. CSS页面渲染优化属性will-change

    前面的话   当我们通过某些行为(点击.移动或滚动)触发页面进行大面积绘制的时候,浏览器往往是没有准备的,只能被动使用CPU去计算与重绘,由于没有事先准备,应付渲染够呛,于是掉帧卡顿.而CSS属性wi ...

  2. CodeForces 725A

    A. Jumping Ball time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  3. HDU5477(模拟)

    A Sweet Journey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  4. java cooki的使用

    session: 当新客户端发现一个HTTP请求时服务端会创建一个session.并分配一个sessionID作为服务端来客户端的识别,session对象会 保存在服务端.此时session对象处天N ...

  5. 遍历ul下的li,点击弹出li的索引

    首先我们需要一个html结构 <div > <ul> <li>a</li> <li>a</li> <li>a< ...

  6. js中的3种弹出式消息提醒(警告窗口,确认窗口,信息输入窗口)的命令式

    alert("A"); confirm("B");var name = confirm("B");if(name){ alert(" ...

  7. oracle_plseq客户端中文乱码

    1.登陆plsql,执行sql语句,输出的中文标题显示成问号????:条件包含中文,则无数据输出 输入sql语句select * from V$NLS_PARAMETERS查看字符集,查看第一行val ...

  8. C++ 头文件系列(fstream)

    1. 简介 该头文定义了与文件箱关联的流类的4个模版: basic_filebuf basic_ifstream basic_ofstream basic_fstream 和8个类型: filebuf ...

  9. STM32的LED驱动程序

    这个LED的小程序基于的是德飞莱的最小系统板 我当时写这个程序的时候想的就是这个程序能够便于理解 也便于移植 便于调用 我参加过电赛 对于STM32的一个管脚修改的麻烦是深有体会 一个地方不对就没法工 ...

  10. 转:Apache 与 Nginx 比较

    Nginx 轻量级,采用 C 进行编写,同样的 web 服务,会占用更少的内存及资源 抗并发,nginx 以 epoll and kqueue 作为开发模型,处理请求是异步非阻塞的,负载能力比 apa ...