题意:在一个地图里逃亡,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. java调用oracle存储过程,返回结果集

    package com.srie.db.pro; import java.sql.CallableStatement; import java.sql.Connection; import java. ...

  2. angular表格分页

    <!doctype html> <html lang="en" > <head> <meta charset="UTF-8&qu ...

  3. SDWebImage源码解读之干货大总结

    这是我认为的一些重要的知识点进行的总结. 1.图片编码简介 大家都知道,数据在网络中是以二进制流的形式传播的,那么我们该如何把那些1和0解析成我们需要的数据格式呢? 说的简单一点就是,当文件都使用二进 ...

  4. express框架介绍

    //引入express模块 var express = require('express'); //调用express方法,接受其返回值(返回值为对象) var app = express(); ap ...

  5. 融云发送手机短信验证短信(.net版本)

    首先本次需求是在MVC5中进行的,通过收费的融云服务来验证手机号码,而且本次的项目也是前后台分离,所以添加了WEBAPI2,那么先添加WEBAPI的接口 using System; using Sys ...

  6. linux上安装Oracle 11g R2 标准版 64位

    一.Oracle 安装前的准备 检查一下包,必须全部安装: binutils-2.20.51.0.2-5.43.el6.x86_64 compat-libstdc++-296-2.96-144.el6 ...

  7. Oracle数据库语言修改成UTF-8

    select * from v$nls_parameters; sqlplus "/ as sysdba" SQL> SHUTDOWN IMMEDIATE SQL> S ...

  8. JavaScript 深浅拷贝

    JavaScript有五种基本数据类型(Undefined, null, Boolean, String, Number),还有一种复杂的数据类型,就是对象. Undefined 其实是已声明但没有赋 ...

  9. 内网穿透+VS2015自带IIS express实现本地调试(微信等需要将开发环境暴漏到外网的情况使用)

    今天一个兼职结束了,又要开始寻找新的兼职公司了 ,为了贴补家用啊,为了给儿子更好的生活加油! 抒情完毕进入正题,本篇文章要解决的问题是其实在开发微信支付,微信公众号等回调地址必须是外网可访问的80端口 ...

  10. Qt 中QString 字符串操作:连接、组合、替换、去掉空白字符

    Qt中的字符串类 QString类 保存了16位Unicode值,提供了丰富的操作.查询和转换等函数. QString 字符串有如下几个操作符: (1) "+" 用于组合两个字符串 ...