Description

Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to find her way to a safe location (one that is never destroyed by a meteor) . She is currently grazing at the origin in the coordinate plane and wants to move to a new, safer location while avoiding being destroyed by meteors along her way.

The reports say that M meteors ( ≤ M ≤ ,) will strike, with meteor i will striking point (Xi, Yi) ( ≤ Xi ≤ ;  ≤ Yi ≤ ) at time Ti ( ≤ Ti  ≤ ,). Each meteor destroys the point that it strikes and also the four rectilinearly adjacent lattice points.

Bessie leaves the origin at time  and can travel in the first quadrant and parallel to the axes at the rate of one distance unit per second to any of the (often ) adjacent rectilinear points that are not yet destroyed by a meteor. She cannot be located on a point at any time greater than or equal to the time it is destroyed).

Determine the minimum time it takes Bessie to get to a safe place.

Input

* Line : A single integer: M
* Lines ..M+: Line i+ contains three space-separated integers: Xi, Yi, and Ti

Output

* Line : The minimum time it takes Bessie to get to a safe place or - if it is impossible.

Sample Input


Sample Output


Source

 
 
有个小文青去看流星雨,不料流星掉下来会砸毁上下左右中五个点。每个流星掉下的位置和时间都不同,求小文青能否活命,如果能活命,最短的逃跑时间是多少?
有个地方给写错了,wa了很久,太粗心了//code 72行
 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<vector>
#include<map>
#include<queue>
using namespace std;
#define N 506
int mp[N][N];
int dirx[]={,,-,};
int diry[]={-,,,};
int vis[N][N];
struct Node{
int x,y,t;
};
int bfs(){
if(mp[][]==-) return ;
if(mp[][]==) return -;
Node s;
s.x=;
s.y=;
s.t=;
vis[][]=;
queue<Node>q;
q.push(s);
Node t1,t2;
while(!q.empty()){
t1=q.front();
q.pop();
for(int i=;i<;i++){
t2.x=t1.x+dirx[i];
t2.y=t1.y+diry[i];
t2.t=t1.t+;
if(t2.x< || t2.x>=N || t2.y< || t2.y>=N) continue;
if(mp[t2.x][t2.y]==-){
return t2.t;
}
if(t2.t>=mp[t2.x][t2.y]) continue;
if(vis[t2.x][t2.y]) continue;
vis[t2.x][t2.y]=;
//mp[t2.x][t2.y]=t2.t;
q.push(t2);
}
}
return -;
}
int main()
{
int m;
while(scanf("%d",&m)==){
memset(mp,-,sizeof(mp));
memset(vis,,sizeof(vis));
for(int i=;i<m;i++){
int x,y,t;
scanf("%d%d%d",&x,&y,&t);
if(mp[x][y]==-){//处理(x,y)这点
mp[x][y]=t;
}
else{
mp[x][y]=min(mp[x][y],t);
} for(int j=;j<;j++){//处理周围4个点
int xx=x+dirx[j];
int yy=y+diry[j];
if(xx< || xx>=N || yy< || yy>=N) continue;
if(mp[xx][yy]==-){
mp[xx][yy]=t;
}
else{
mp[xx][yy]=min(mp[xx][yy],t);
}
}
} printf("%d\n",bfs()); }
return ;
}

poj 3669 Meteor Shower(bfs)的更多相关文章

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

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

  2. POJ 3669 Meteor Shower(流星雨)

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

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

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

  4. poi 3669 meteor shower (bfs)

    题目链接:http://poj.org/problem?id=3669 很基础的一道bfs的题,然而,我却mle了好多次,并且第二天才发现错在了哪里_(:з)∠)_ 写bfs或者dfs一定要记得对走过 ...

  5. 【POJ - 3669】Meteor Shower(bfs)

    -->Meteor Shower Descriptions: Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平 ...

  6. POJ 3669 Meteor Shower【BFS】

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

  7. POJ 3369 Meteor Shower (BFS,水题)

    题意:给定 n 个炸弹的坐标和爆炸时间,问你能不能逃出去.如果能输出最短时间. 析:其实这个题并不难,只是当时没读懂,后来读懂后,很容易就AC了. 主要思路是这样的,先标记所有的炸弹的位置,和时间,在 ...

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

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

  9. poj 3669 Meteor Shower

                                                                                                      Me ...

随机推荐

  1. editplus批量删除html代码空行

    在editplus替换菜单功能里,“查找”功能里输入: ^[ \t]*\n 替换为空,然后“全部替换”即可. 替换时,要选择“正则表达式”选项, 详细:http://www.dedecms8.com/ ...

  2. 【转】Devexpress使用之:GridControl控件(合并表头)

    Devexpress系列控件功能很强大,使用起来也不太容易,我也是边摸索边使用,如果有时间我会把常用控件的使用方法整理出来的. using System; using System.Collectio ...

  3. C/C++变量命名规则

    变量命名规则是为了增强代码的可读性和easy维护性. 变量命名规则: 一.用最短字符表示最准确的意义. 二.使用变量前缀. 1.  整型前缀 int               nId;        ...

  4. hdu 4405 Aeroplane chess (概率DP)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. Swift 2.0 封装图片折叠效果

    文/猫爪(简书作者)原文链接:http://www.jianshu.com/p/688c491580e3著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 用Swift封装图片折叠效果 b ...

  6. 用SNMP协议实现系统信息监控--Windows Server 2008

    简单了解: SNMP简单网络管理协议,是一种属于应有层的协议,主要有三个部分组成,被管理部分.代理部分和网络管理系统. 被管理部分是一个网络节点,也称为网络单元.SNMP代理是被管理设备上的一个网络管 ...

  7. asp.net mvc 删除栏目、栏目下又有子栏目的处理方式

  8. DataSource

    数据库连接池原理:在内存中开辟一段存储空间用来存储多个Connection连接,避免频繁的创建Connection,从而提高效率.代码如下: package jcbc.ds.test1; import ...

  9. ubuntu终端命令

    整个电脑都划成ubuntu用. 装软件时的一个明显感觉就是很多事情,用终端的命令行去做很容易,用图形界面往往很复杂,而且很多时候还会出现权限的问题,对于ubuntu的用户权限,现在的唯一感觉就是权限在 ...

  10. jade的基本语法

    - for (var i=0;i<3;i++) li scnu-learn //这里的=,默认会转义内容 p= "Welcome scnu <strong>good< ...