题目链接:

https://vjudge.net/problem/POJ-3669

题目大意:

巨大流星雨即将袭来。每个流星会对击中的地方以及周围(上下左右四格)造成破坏。Bessie开始时位于(0, 0)位置,并希望逃到一处不会被袭击到的地方(在第一象限内)。已知每移动一格需要1个时间单位,被流星破坏后的地方不能再进入。给出M个流星在T时刻击中的地方(X, Y),问Bessie能否逃到安全的地方,若能输出最短时间,否则输出-1。

思路:

预处理出每个点的最小爆炸时间,然后从(0,0)开始BFS,注意一个坑点,如果0时刻炸到了0 0 点那就直接输出-1,还有一个坑点就是不能局限于300*300的MAP,300*300的边界会WA,301*301的边界就过了,是因为的流星炸到300*300以内,肯需要逃离到301那一行才行

 #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<cmath>
using namespace std;
typedef pair<int, int> Pair;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int T, n, m, d;
const int maxn = 1e5 + ;
int Map[][];//Map[i][j]表示ij这个点的最短
int dir[][] = {,,,,-,,,-};
bool vis[][];
struct node
{
int x, y, time;
node(int x, int y, int time):x(x), y(y), time(time){}
node(){}
};
int bfs()
{
queue<node>q;
q.push(node(,,));
vis[][] = ;
while(!q.empty())
{
node now = q.front();
q.pop();
//cout<<now.x<<" "<<now.y<<" "<<now.time<<endl;
if(Map[now.x][now.y] == INF)
{
return now.time;
}
for(int i = ; i < ; i++)
{
int xx = now.x + dir[i][];
int yy = now.y + dir[i][];
node next(xx, yy, now.time + );
if(xx < || xx > || yy < || yy > )continue;
if(vis[xx][yy])continue;
if(Map[xx][yy] <= next.time)continue;
vis[xx][yy] = ;
q.push(next);
}
}
return -;
}
int main()
{
cin >> n;
int x, y, w;
memset(Map, INF, sizeof(Map));
for(int i = ; i < n; i++)
{
scanf("%d%d%d", &x, &y, &w);
Map[x][y] = min(Map[x][y], w);
for(int i = ; i < ; i++)
{
int xx = x + dir[i][];
int yy = y + dir[i][];
if(xx >= && yy >= )
Map[xx][yy] = min(Map[xx][yy], w);
}
}
if(Map[][] == )//特判
{
cout<<"-1"<<endl;
return ;
}
cout<<bfs()<<endl;
return ;
}

POJ-3669 Meteor Shower---BFS+预处理的更多相关文章

  1. POJ 3669 Meteor Shower BFS求最小时间

    Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31358   Accepted: 8064 De ...

  2. POJ 3669 Meteor Shower BFS 水~

    http://poj.org/problem?id=3669 题目大意: 一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达 ...

  3. POJ 3669 Meteor Shower(流星雨)

    POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS    Memory Limit: 65536K Description 题目描述 Bessie hears ...

  4. POJ 3669 Meteor Shower (BFS+预处理)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  5. POJ 3669 Meteor Shower【BFS】

    POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...

  6. poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  7. 题解报告:poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  8. poj 3669 Meteor Shower

                                                                                                      Me ...

  9. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  10. poj3669 Meteor Shower(BFS)

    题目链接:poj3669 Meteor Shower 我只想说这题WA了后去看讨论才发现的坑点,除了要注意原点外,流星范围题目给的是[0,300],到302的位置就绝对安全了... #include& ...

随机推荐

  1. sshd服务及系统文件传输

    一.sshd 简介 sshd= secure shell 可以通过网络在主机中开机shell的服务 客户端软件 sshd 连接方式: ssh username@ip          ##文本模式的链 ...

  2. linux下lua运行环境安装

    1.下载安装包: [root@H0f ~]# wget  http://www.lua.org/ftp/lua-5.2.4.tar.gz    http://www.lua.org/ftp/lua-5 ...

  3. linux 6 查看防火墙状态及开启关闭命令

    linux 6 查看防火墙状态及开启关闭命令 https://blog.csdn.net/lv_shijun/article/details/52453882 存在以下两种方式: 一.service方 ...

  4. my.资料__烹饪炼药

    ZC: 新区的时候,烹饪炼药 也不是 等级越高越好:等级越高需要的人可能少,价格高 但是买的人少:大家都在那个等级 很容易堵车 没有摊位... 刚开始 大家都穷 可能等级稍低的 反而好卖... ZC: ...

  5. 自定义element-ui主题

    自定义element主题颜色:主要参考这个文章https://blog.csdn.net/wangcuiling_123/article/details/78513245,再自己做了一遍成功.感谢. ...

  6. Index Skip Scan in Oracle in 11g

    http://viralpatel.net/blogs/oracle-index-skip-scan/ in 11g the same sql use index skip scan but in 1 ...

  7. Select语句完整的执行顺序

    Select语句完整的执行顺序:1.from子句组装来自不同数据源的数据:2.where子句基于指定的条件对记录行进行筛选:3.group by子句将数据划分为多个分组:4.使用聚集函数进行计算:5. ...

  8. TCP/IP协议中几个缩写词的含义 MSL、TTL和RTT 报文最大生存时间 跳数(即生存时间) cs往返时间 MSL要大于TTL知道为什么吗?

    MSL.TTL和RTT简介 1.MSL是Maximum Segment Lifetime英文的缩写,中文可以译为“报文最大生存时间”,他是任何报文在网络上存在的最长时间,超过这个时间报文将被丢弃.因为 ...

  9. Android NDK开发 图片处理(五)

    做过Java的同学可能经常会遇到一些关于图片处理的 例如类似QQ离线头像显示灰的.最快的算法是用colorMatrix来实现.这里通过Java调用JNI来处理每一个像素来实现. 对每一个像素点取出RG ...

  10. inventor安装失败怎样卸载安装inventor 2016?

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...