博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Meteor Shower POJ - 3669
阅读量:4320 次
发布时间:2019-06-06

本文共 2114 字,大约阅读时间需要 7 分钟。

    Meteor Shower

 

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
40 0 22 1 21 1 20 3 5
Sample Output
5

题解+解析:

#include 
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;int move[5][2] = {1,0,0,1,-1,0,0,-1,0,0};struct Meteor{ int x, y, t; Meteor(int _x, int _y, int _t){x = _x; y= _y; t=_t;} Meteor(){}};typedef Meteor P;Meteor input[50000];int map[350][350];bool visit[350][350]; //不走重复的,重复走的点说明该走法一定不是最优的。 不判重的话回TLE。int last = -1;int bfs(){ memset(visit, 0, sizeof(visit)); queue

que; P cor(0,0,0); que.push(cor); while (que.size()) { cor = que.front(); for (int i = 0; i < 4; i++) { int nx = cor.x+move[i][0], ny = cor.y+move[i][1]; if (0<=nx&&0<=ny&&cor.t+1

转载于:https://www.cnblogs.com/focus5679/p/9286181.html

你可能感兴趣的文章
20165309 实验四 Android程序设计
查看>>
团队博客目录
查看>>
linux的启动流程
查看>>
摩尔斯电码(Morse Code)Csharp实现
查看>>
C#NULL条件运算符
查看>>
使用GZIP压缩网页内容(一)
查看>>
《深入浅出MFC》第二章 C++的重要性质
查看>>
关于智能硬件设备shell安全设计
查看>>
homework1
查看>>
3选择结构程序设计
查看>>
Python学习 12day__高级语法
查看>>
关于做产品的一点思考
查看>>
超大地形的处理 (Terrain Visualization)【转自知乎】
查看>>
html知识2
查看>>
Python—面向对象01
查看>>
Android DDMS ADB Hierarchy Viewer Lint
查看>>
Linux命令学习(5):more和less
查看>>
Linux 三剑客之sed命令总结
查看>>
倒计时
查看>>
36.Altium Designer(Protel)网络连接方式Port和Net Label详解
查看>>