题意:在一个地图里逃亡,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. CCNA网络工程师学习进程(9)GNS3的安装与配置

        本节将简单介绍一下网络设备模拟软件GNS3的配置和使用方法.     (1)GNS3概述: GNS3是一款具有图形化界面可以运行在多平台(包括Windows, Linux, and MacOS ...

  2. 使用 Passenger +Apache扩展 Puppet,代替其Webrick的web框架

    使用 Passenger +Apache扩展 Puppet,代替其Webrick的web框架 1安装 yum install ruby-devel ruby-libs rubygems libcurl ...

  3. HDU1716(全排列)

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. .Net学习难点讨论系列17 - 线程本地变量的使用

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  5. ubuntu14.04下手动安装eclipse

    ubuntu14.04下手动安装eclipse 第一步: 安装jdk 第二步: 下载eclipse,假设下载的文件文件名为eclipse.tar.gz 第三步: 解压 sudo -zxvf ./ecl ...

  6. 众人拾柴火焰高之Tomcat集群

    一人拾柴火不旺,众人拾柴火焰高.Tomcat服务器也是一样,一台服务器再强大能承受的访问也是有限的.要提供高并发.高可用的服务,就必须横向扩展,多台Tomcat组成一个集群,根据实际的访问量动态增减服 ...

  7. IOS9.0 之后友盟分享详细过程

    一: 申请友盟的AppKey(友盟的Key是根据应用的名称生成的!) 在友盟注册了你自己的开发者账号后就可以申请AppKey了.然后在这个方法里面设置Key - (BOOL)application:( ...

  8. 关于js的parseInt方式在不同浏览器下的表现

    今天开发期间遇到个需求要把日期格式转换成毫秒数 日期为:2015-08-10 split之后使用parseInt将2015,08,10分别转化为数字格式. 但是使用parseInt('08')的时候却 ...

  9. keepalived原理

    Keepalived的作用是检测服务器的状态,如果有一台web服务器死机,或工作出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时使用其他服务器代替该服务器的工作,当服务器工 ...

  10. Javascript高级程序设计——语法、关键字、保留字、变量、数据类型

    1.了解基本语法,JS大小写区分.注释风格.什么是严格模式等. 2.知道ES3和ES5的关键字和保留字大概有哪些,如果使用关键字会报什么错,使用保留字决定于特定浏览器引擎. 3.全局变量和局部变量的定 ...