poj 3669 Meteor Shower(bfs)
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
#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)的更多相关文章
- 题解报告:poj 3669 Meteor Shower(bfs)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- POJ 3669 Meteor Shower(流星雨)
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS Memory Limit: 65536K Description 题目描述 Bessie hears ...
- POJ 3669 Meteor Shower (BFS+预处理)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- poi 3669 meteor shower (bfs)
题目链接:http://poj.org/problem?id=3669 很基础的一道bfs的题,然而,我却mle了好多次,并且第二天才发现错在了哪里_(:з)∠)_ 写bfs或者dfs一定要记得对走过 ...
- 【POJ - 3669】Meteor Shower(bfs)
-->Meteor Shower Descriptions: Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平 ...
- POJ 3669 Meteor Shower【BFS】
POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...
- POJ 3369 Meteor Shower (BFS,水题)
题意:给定 n 个炸弹的坐标和爆炸时间,问你能不能逃出去.如果能输出最短时间. 析:其实这个题并不难,只是当时没读懂,后来读懂后,很容易就AC了. 主要思路是这样的,先标记所有的炸弹的位置,和时间,在 ...
- POJ 3669 Meteor Shower BFS求最小时间
Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31358 Accepted: 8064 De ...
- poj 3669 Meteor Shower
Me ...
随机推荐
- MySQL具体解释(7)-----------MySQL线程池总结(一)
线程池是Mysql5.6的一个核心功能.对于server应用而言,不管是web应用服务还是DB服务,高并发请求始终是一个绕不开的话题.当有大量请求并发訪问时,一定伴随着资源的不断创建和释放.导致资源利 ...
- 写一个段落python代码推理list深浅
主要是针对嵌套列表问题. 列表套列表,究竟子列表那个更深... 这个问题想着就烦.假设嵌套10000万个列表是不是要统计10000个数再排序呢? 最后想了想用 list的extend功能 加上递归函数 ...
- git config配置文件 (共有三个配置文件)
设置 git status的颜色. git config --global color.status auto 一.Git已经在你的系统中了,你会做一些事情来客户化你的Git环境.你只需要做这些设置一 ...
- NVL函数(NVL,NVL2,NULLIF,COALESCE)
NVL 语法:NVL( expr1, expr2) 功能:如果expr1为NULL,则NVL函数返回expr2的值,否则返回expr1的值,如果两个参数的都为NULL ,则返回NULL. 注意事项:e ...
- Java ------------获取不会重复的随机数
import java.util.UUID; public class UTest { public static void main(String[] args) { //UUID通过rand ...
- AngularJs练习Demo8 自定义过滤器
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...
- IOS 错误集合以及解决办法(持续整理中)
1 . 如下错误: app:resource fork, Finder information, or similar detritus not al site:forums.developer.ap ...
- 一行代码设置UITableView分割线的长度
使用UITableView时会发现分割线的长度是这样的: 而QQ里面分割线左端到昵称的下面就截止了: 只需行代码就可以搞定: self.tableView.separatorInset = UIEdg ...
- 再入门JavaScript
从去年毕业到现今,工作不到一年.接触了3个实际项目,一个实训项目.却反而只有实训项目做的比较像样子. 重新又回到写脚本的岗位上,第一次真正意义上接触脚本应该是在达内培训时候李大神所引进,大神各种技术, ...
- C/C++中的虚析构函数和私有析构函数的使用
代码: #include <iostream> using namespace std; class A{ public: A(){ cout<<"construct ...