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 ...
随机推荐
- java 字符串为空问题
java 字符串为空问题 String testStr = null; System.out.println(testStr); if (testStr == null) { System.out.p ...
- 大话分页(补充)——Threadlocal封装offSet和pageSize简化分页工具类
经过前两篇文章(大话分页一.大话分页二)的介绍,我认为我想介绍的东西已经介绍完了,不过想精益求精的童鞋可以继续看本篇文章. 在第一篇文章中介绍了一个分页的工具类(具体请看大话分页一),从实现功能上来说 ...
- 【Cocos2d-X开发学习笔记】第19期:动作管理类(CCActionManager)的使用
本系列学习教程使用的是cocos2d-x-2.1.4(最新版为3.0alpha0-pre) ,PC开发环境Windows7,C++开发环境VS2010 一.动作管理类 动作管理类CCActionMan ...
- Timus 1796. Amusement Park 聪明题
On a sunny Sunday, a group of children headed by their teacher came to an amusement park. Aunt Frosy ...
- ubuntu16.04 server安装小记
由于本人有一台闲置的thinkpad电脑,所以打算在上边安装一个ubuntu16.04 server版本,其中遇到主要问题,做一下记录: 安装过程中出现“ubuntu16.04 server64 bu ...
- Code First 数据注释--DatabaseGenerated
EF中可以使用DatabaseGenerated设置数据库字段的属性,它有三个枚举值:Computed.None.Identity Computed 表示这一列是计算所得 None 不做处理 Iden ...
- MVC 路由Router
Url路由将进入的请求发送给控制器操作. url路由使用路由表处理进入的请求 此路由表在应用程序第一次启动时创建. 路由表在Global.asax文件中设置
- 《第一行代码》学习笔记3-活动Activity(1)
1.活动-一种可以包含用户界面的组件,用于和用户进行交互. <Button android:id="@+id/button_1" android:layout_width=& ...
- java 静态文件使用注解
spring框架为我们代码的编写带来了极大的便利,特别是注解的使用.但是有个问题,当我们在静态文件中使用注解的时候,这个时候就会报错了.如以下代码: @Autowired private UserSe ...
- ssh-agent自启动加key脚本
公司使用到阿里云. 需要使用 ssh-agent forward 来跳转.为了方便自己就写了这个脚本 1 #!/bin/sh 2 # auto start ssh-agent and add key ...