POJ-3669
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 (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.
Input
* Line 1: A single integer: M
* Lines 2..M+1: Line i+1 contains three space-separated integers: Xi, Yi, and TiOutput
* 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 5Sample 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的更多相关文章
- POJ 3669 Meteor Shower【BFS】
POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...
- POJ 3669 Meteor Shower(流星雨)
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS Memory Limit: 65536K Description 题目描述 Bessie hears ...
- 广搜最短路(最短时间到达目的地),POJ(3669)
题目链接:http://poj.org/problem?id=3669 解题报告: 1.流星坠落的点,四周和自己本身都被毁灭,不断更新每个点被毁灭的时候的最短时间. 2.搜索终点是,到达某个点,这个不 ...
- POJ 3669 Meteor Shower BFS 水~
http://poj.org/problem?id=3669 题目大意: 一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达 ...
- 【POJ 3669 Meteor Shower】简单BFS
流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...
- poj 3669 线段树成段更新+区间合并
添加 lsum[ ] , rsum[ ] , msum[ ] 来记录从左到右的区间,从右到左的区间和最大的区间: #include<stdio.h> #define lson l,m,rt ...
- BFS:Meteor Shower(POJ 3669)
奔跑吧,傻牛 题目大意:这只Bessie的牛又要来闹事了,这次她的任务就是来躲流星雨,流星雨就是在一定时间会从天上砸到Bessie的所在的正方形区域内(Bessie在0,0的位置),然后砸下 ...
- poj 3669 Meteor Shower
Me ...
- POJ 3669 广度优先搜索
题意:巨大流星雨即将袭来.每个流星会对击中的地方以及周围(上下左右四格)造成破坏.Bessie开始时位于(0, 0)位置,并希望逃到一处不会被袭击到的地方(在第一象限内).已知每移动一格需要1个时间单 ...
- poj 3669 Meteor Shower(bfs)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
随机推荐
- Grails 简要
一.什么是Grails? Grails is an Open Source, full stack, web application framework for the JVM. It takes a ...
- struts2 Eclipse 中集成strust2开发框架实例
下面通过建立一个小的实例具体来说明Eclipse 集成struts2,以下实例采用的为 struts2 版本为 struts2 2.2.3.1 为应用. 1. 下载struts2的开发包 第一步: 在 ...
- Entity Framework 4.1:多对多的关系
这篇文章讨论多对多的关系. 让我们从最简单的例子开始.我们让 EF4.1 来推断表的映射.我在订单和雇员之间建模多对多的关系. )] publicstring CustomerName { get; ...
- getStorageSync const UID = this.$parent.UID wx.getStorageSync('UID')
getStorageSync 在程序运行中是在内存 还是去文件系统读取? const UID = this.$parent.UID wx.getStorageSync('UID') ...
- Xshell 连接centOS虚拟机、centOS内置python版本升级
Xshell 连接虚拟机 前置条件:VMware Workstation 12.5.1.Xshell 5 . centOS 6.6 1.打开虚拟机,输入用户名和密码: 2.输出命令:ifconfig ...
- 【题解】CF45G Prime Problem
[题解]CF45G Prime Problem 哥德巴赫板子题? \(\frac{n(n+1)}{2}\)若是质数,则不需要分了. 上式 若是奇数,那么拆成2和另一个数. 上式 若是偶数吗,直接\(O ...
- (C)结构数组
结构数组 对于大小相同但是类型不同的数组,定义结构体数组对其很有帮组.例如: char *keyword[NKEYS]; int keycount[NKEYS]; 这两个数组大小相同,因此 可以用另一 ...
- python列表切片
Python中符合序列的有序序列都支持切片(slice),例如列表,字符串,元组. 格式:[start:end:step] start:起始索引,从0开始,-1表示结束 end:结束索引 step:步 ...
- BZOJ 1604 [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居:队列 + multiset + 并查集【曼哈顿距离变形】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1604 题意: 平面直角坐标系中,有n个点(n <= 100000,坐标范围10^9) ...
- 分享知识-快乐自己: Oracle数据库实例、用户、表、表空间之间关系
数据库: Oracle数据库是数据的物理存储.这就包括(数据文件ORA或者DBF.控制文件.联机日志.参数文件). 其实Oracle数据库的概念和其它数据库不一样,这里的数据库是一个操作系统只有一个库 ...