POJ 3669 Meteor Shower(流星雨)
POJ 3669 Meteor Shower(流星雨)
Time Limit: 1000MS Memory Limit: 65536K
|
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 (Xi, Yi) (0 ≤ Xi ≤ 300; 0 ≤ Yi ≤ 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. |
Bessie听说有场史无前例的流星雨即将来临;有谶言:陨星将落,徒留灰烬。为保生机,她誓将找寻安全之所(永避星坠之地)。目前她正在平面坐标系的原点放牧,打算在群星断其生路前转移至安全地点。 此次共有M (1 ≤ M ≤ 50,000)颗流星来袭,流星i将在时间点Ti (0 ≤ Ti ≤ 1,000) 袭击点 (Xi, Yi) (0 ≤ Xi ≤ 300; 0 ≤ Yi ≤ 300)。每颗流星都将摧毁落点及其相邻四点的区域。 Bessie在0时刻时处于原点,且只能行于第一象限,以平行与坐标轴每秒一个单位长度的速度奔走于未被毁坏的相邻(通常为4)点上。在某点被摧毁的刹那及其往后的时刻,她都无法进入该点。 |
|
Input |
输入 |
|
* Line 1: A single integer: M * Lines 2..M+1: Line i+1 contains three space-separated integers: Xi, Yi, and Ti |
* 第1行: 一个整数: M * 第2..M+1行: 第i+1行包含由空格分隔的三个整数: Xi, Yi, and Ti |
|
Output |
输出 |
|
* Line 1: The minimum time it takes Bessie to get to a safe place or -1 if it is impossible. |
* 仅一行: Bessie寻得安全点所花费的最短时间,无解则为-1。 |
|
Sample Input - 输入样例 |
Sample Output - 输出样例 |
4 |
5 |
【题解】
从起点开始进行SPFA(DFS)即可。
需要注意的是在读取各个落点的数据时,只保留最早被毁灭的时间点。
【代码 C++】
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define mx 305
int dg[mx][mx], tim[mx][mx], drc[][] = { , , -, , , , , -, , };
struct Point{
int y, x;
}temp, nxt;
int main(){
int m, x, y, t, i, nowT, opt;
scanf("%d", &m);
memset(dg, -, sizeof(dg));
while (m--){
scanf("%d%d%d", &x, &y, &t);
++y; ++x;
for (i = ; i < ; ++i){
temp.y = y + drc[i][]; temp.x = x + drc[i][];
if (~dg[temp.y][temp.x]) dg[temp.y][temp.x] = std::min(dg[temp.y][temp.x], t);
else dg[temp.y][temp.x] = t;
}
} memset(dg, , sizeof(dg[])); memset(dg[mx - ], , sizeof(dg[]));
for (i = ; i < mx; ++i) dg[i][] = dg[i][mx - ] = ;
memset(tim, , sizeof(tim));
nowT = ; opt = ;
std::queue<Point> q;
tim[][] = ; temp.y = temp.x = ; q.push(temp);
while (!q.empty()){
temp = q.front(); q.pop();
if (dg[temp.y][temp.x] == -){
opt = std::min(opt, tim[temp.y][temp.x]);
continue;
}
for (i = ; i < ; ++i){
nxt.y = temp.y + drc[i][]; nxt.x = temp.x + drc[i][];
if (tim[temp.y][temp.x] + < dg[nxt.y][nxt.x] || dg[nxt.y][nxt.x] == -){
if (tim[temp.y][temp.x] + < tim[nxt.y][nxt.x]){
tim[nxt.y][nxt.x] = tim[temp.y][temp.x] + ;
q.push(nxt);
}
}
}
}
if (opt == ) puts("-1");
else printf("%d", opt);
return ;
}
POJ 3669 Meteor Shower(流星雨)的更多相关文章
- POJ 3669 Meteor Shower【BFS】
POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...
- poj 3669 Meteor Shower
Me ...
- poj 3669 Meteor Shower(bfs)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- POJ 3669 Meteor Shower (BFS+预处理)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- 题解报告:poj 3669 Meteor Shower(bfs)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- POJ 3669 Meteor Shower BFS求最小时间
Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31358 Accepted: 8064 De ...
- 【POJ 3669 Meteor Shower】简单BFS
流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...
- POJ 3669 Meteor Shower BFS 水~
http://poj.org/problem?id=3669 题目大意: 一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达 ...
- BZOJ1611: [Usaco2008 Feb]Meteor Shower流星雨
1611: [Usaco2008 Feb]Meteor Shower流星雨 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 904 Solved: 393 ...
随机推荐
- C#调用opencv
最经做一个项目,底层调用openCV编写的图像处理程序,用户界面采用C#编写. 于是学习了相关技术,总结如下: C#编写的是托管代码,编译生成微软中间语言,而普通C++代码则编译生成本地机器码,这两种 ...
- Objective-C语言的面向对象特性
Objective-C作为一种面向对象的编程语言,具有面向对象的基本特征,即:封装.继承和多态.主要介绍Objective-C中有关面向对象基本概念:类.对象.方法和属性等. 类是Objective- ...
- Delphi中使用@取函数地址的问题(转)
Delphi中使用@取函数地址的问题 例如以下代码:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes ...
- anroid 查看签名信息的方法
1.把app改成压缩文件 2.解压以后找到META-INF\CERT.RSA 3.在CMD命令行里面输入: keytool -printcert -file E:\META-INF\CERT.RS ...
- iOS 序列化与反序列化
开篇 1到底这个序列化有啥作用? 面向对象的程序在运行的时候会创建一个复杂的对象图,经常要以二进制的方法序列化这个对象图,这个过程叫做Archiving. 二进制流可以通过网络或写入文件中(来源于某教 ...
- The C++ Standard Library --- A Tutorial Reference 读书笔记
5.2 Smart Pointer(智能指针) shared_ptr的aliasing构造函数,接受一个shared pointer和一个raw pointer.它允许你掌握一个事实:某对象拥有另一个 ...
- expect语法
沙河西ftp上传,使用了expect语言的脚本. 我们经常会遇到一些需要与服务器程序打交道的场景,比如,从登陆某个服务器,然后进行某项工作.这很平常,但是如果把这个工作自动化进行,你就需要一个程序能自 ...
- [Ogre][地形]OgreTerrain的实现原理分析
转自:http://www.xuebuyuan.com/1482609.html 一.世界地图 将整个世界切分成多个Tile,每个Tile大小相同,用二维坐标形式索引起来,如图: 中心点(0,0)位置 ...
- ACM题目————STL练习之Ananagrams
Description Most crossword puzzle fans are used to anagrams--groups of words with the same letters i ...
- 编写一个函数func(),将此函数的输入参数(int型)逆序输出显示,如54321 –> 12345,要求使用递归,并且函数体代码不超过8行
public class Test{ //中间变量 private String res = "0"; //方法 public int func(int i){ if(i>0 ...