Meteor Shower
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 21055   Accepted: 5499

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 (1 ≤ M ≤ 50,000) will strike, with meteor i will striking point (XiYi) (0 ≤ X≤ 300; 0 ≤ Y≤ 300) at time Ti (0 ≤ Ti  ≤ 1,000). Each meteor destroys the point that it strikes and also the four rectilinearly adjacent lattice points.

Bessie leaves the origin at time 0 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 4) 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 1: A single integer: M
* Lines 2..M+1: Line i+1 contains three space-separated integers: XiYi, and Ti

Output

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

Sample Input

4
0 0 2
2 1 2
1 1 2
0 3 5

Sample Output

5

题意:

输入m组数,每组分别代表x,y坐标和陨石落在改点时的时间t。从零点出发,问是否有生还的可能。

设mp数组初始值为-1,然后存入时间t。

用bfs层次遍历直到找出mp==-1的点,返回现在的t。

AC代码:

 //#include<bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <list>
#include <sstream>
#include <set>
#include <functional>
using namespace std; const int MAX=; struct node{
int x;int y;int t;
}s,temp; int m;
int mp[MAX][MAX];
int dir[][]={{,},{,},{,},{-,},{,-}};
queue<node> q; int bfs(){
if(mp[][]==-) return ;
if(mp[][]==) return -;
s.x=;
s.y=;
s.t=;
q.push(s);
while(!q.empty()){
temp=q.front();
q.pop();
for(int i=;i<;i++){
s.x=temp.x+dir[i][];
s.y=temp.y+dir[i][];
s.t=temp.t+;
if(s.x<||s.x>=MAX||s.y<||s.y>=MAX) continue;
if(mp[s.x][s.y]==-) return s.t;
if(mp[s.x][s.y]<=s.t) continue;
mp[s.x][s.y]=s.t;
q.push(s);
}
}
return -;
} int main(){
ios::sync_with_stdio(false);
cin>>m;
memset(mp,-,sizeof(mp));
while(m--){
int x,y,t;
cin>>x>>y>>t;
for(int i=;i<;i++){
int nx=x+dir[i][];
int ny=y+dir[i][];
if(nx<||nx>=MAX||ny<||ny>=MAX)
continue;
if(mp[nx][ny]==-)
mp[nx][ny]=t;
else
mp[nx][ny]=min(mp[nx][ny],t);
}
}
cout<<bfs()<<endl;
return ;
}

POJ-3669的更多相关文章

  1. POJ 3669 Meteor Shower【BFS】

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

  2. POJ 3669 Meteor Shower(流星雨)

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

  3. 广搜最短路(最短时间到达目的地),POJ(3669)

    题目链接:http://poj.org/problem?id=3669 解题报告: 1.流星坠落的点,四周和自己本身都被毁灭,不断更新每个点被毁灭的时候的最短时间. 2.搜索终点是,到达某个点,这个不 ...

  4. POJ 3669 Meteor Shower BFS 水~

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

  5. 【POJ 3669 Meteor Shower】简单BFS

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

  6. poj 3669 线段树成段更新+区间合并

    添加 lsum[ ] , rsum[ ] , msum[ ] 来记录从左到右的区间,从右到左的区间和最大的区间: #include<stdio.h> #define lson l,m,rt ...

  7. BFS:Meteor Shower(POJ 3669)

         奔跑吧,傻牛 题目大意:这只Bessie的牛又要来闹事了,这次她的任务就是来躲流星雨,流星雨就是在一定时间会从天上砸到Bessie的所在的正方形区域内(Bessie在0,0的位置),然后砸下 ...

  8. poj 3669 Meteor Shower

                                                                                                      Me ...

  9. POJ 3669 广度优先搜索

    题意:巨大流星雨即将袭来.每个流星会对击中的地方以及周围(上下左右四格)造成破坏.Bessie开始时位于(0, 0)位置,并希望逃到一处不会被袭击到的地方(在第一象限内).已知每移动一格需要1个时间单 ...

  10. poj 3669 Meteor Shower(bfs)

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

随机推荐

  1. myql 5.6 安装

    环境: centos 6.5  192.168.9.28  4核4G 虚拟机 一. 安装编译源码所需要的工具和库 [root@localhost ~]# yum -y install gcc gcc- ...

  2. WCF基础之设计和实现服务协定

    本来前面还有一个章节“WCF概述”,这章都是些文字概述,就不“复制”了,直接从第二章开始. 当然学习WCF还是要些基础的.https://msdn.microsoft.com/zh-cn/hh1482 ...

  3. SQL语句备份和还原数据库(转)

    1,使用SQL最简单备份,还原数据库 1 /* 备份 */ 2 backup database Test to disk='D:/Test.bak' 3 /* 还原 */ 4 restore data ...

  4. 安装postgresql碰到Unable to write inside TEMP environment path

    搞了半天,原来是 AVAST搞的鬼,把原来注册表的键值改成它自己了.其实应该是 C:\Windows\System32\vbscript.dll The answer in the following ...

  5. angularJs自定义模块

    <script type="text/javascript"> var myApp = angular.module("myApp",[]); my ...

  6. Java for LeetCode 087 Scramble String

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...

  7. linux版本查看命令

    uname -a显示电脑以及操作系统相关信息 cat /proc/version显示正在运行的内核版本 cat /etc/issue或cat /etc/redhat-release  Linux查看版 ...

  8. View源码-Touch事件

    在Android-27中查看源码: 首先我们来查看单个View的触摸事件的处理,在View的dispatchTouchEvent方法中看看源码是如何处理的. public boolean dispat ...

  9. Matlab图像处理(01)-Matlab基础

    枫竹梦对于Matlab几乎是零基础,只是在上学的时候稍稍接触一点,万万没有想到现在还能用到Matlab.进入正题>>> 图像的基本概念 一幅图像可以被定义为一个二维函数f(x,y), ...

  10. c# wpf ComboBox 动态下拉框 及 动态默认值设定

    1.下拉框声明 <ComboBox x:Name="DirComboBox" Width="150" Height="18" Marg ...