【POJ 3669 Meteor Shower】简单BFS
流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间。
对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封锁)。安全地带为永远不会被封锁的点。
简单bfs,开始WA在把平面空间上限当成300*300,但根据题目,这只是有流星雨撞击的范围。实际可走的空间理论上没上限,但分析可得,离原点最近的安全地带一定在(302,302)范围内,所以应可把数组至少开为303*303。
后来WA在把G[0][0]==1的情况也归为无解了。这是没想清楚预处理的意义。。。
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std; const int INF=;
const int MAX_N=;//流星雨落在(300,300)以内,所以最近的安全点一定在(302,302)以内
int m;
int G[MAX_N+][MAX_N+];
int dx[]={,,,-},dy[]={,-,,};
int vis[MAX_N+][MAX_N+]; struct Node
{
int x,y,time;
Node(){}
Node(int xx,int yy,int t):x(xx),y(yy),time(t){}
}; int inside(int x,int y)
{
if(x<||y<||MAX_N<x||MAX_N<y) return ;
else return ;
} int bfs()
{
memset(vis,,sizeof(vis));
if(G[][]==INF) return ;
if(G[][]==) return -;//当G[0][0]==1时,不代表没希望逃走。。。
//因为G数组经过预处理了,把每颗流星雨的影响都表达为每个点的封锁时间
queue<Node> que;
que.push(Node(,,));
vis[][]=;
while(!que.empty())
{
Node cur=que.front();
que.pop();
if(G[cur.x][cur.y]==INF) return cur.time;
for(int i=;i<;i++)
{
int nx=cur.x+dx[i];
int ny=cur.y+dy[i];
if(!inside(nx,ny)) continue;
if(vis[nx][ny]) continue;
if(G[nx][ny]<=cur.time+) continue;
que.push(Node(nx,ny,cur.time+));
vis[nx][ny]=;
}
}
return -;
} int main()
{
freopen("3669.txt","r",stdin);
scanf("%d",&m);
for(int i=;i<=MAX_N;i++)
for(int j=;j<=MAX_N;j++)
G[i][j]=INF;
for(int i=;i<m;i++)
{
int x,y,t;
scanf("%d%d%d",&x,&y,&t);
G[x][y]=min(t,G[x][y]);
for(int i=;i<;i++)
{//把G数组预处理为每个点的最早封锁时间
int nx=x+dx[i];
int ny=y+dy[i];
if(!inside(nx,ny)) continue;
G[nx][ny]=min(t,G[nx][ny]);
}
}
printf("%d\n",bfs());
return ;
}
还是考虑问题不全面不清晰啊。。。多做题多总结吧
【POJ 3669 Meteor Shower】简单BFS的更多相关文章
- POJ 3669 Meteor Shower【BFS】
POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...
- 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(流星雨)
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS Memory Limit: 65536K Description 题目描述 Bessie hears ...
- POJ 3669 Meteor Shower BFS求最小时间
Meteor Shower Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31358 Accepted: 8064 De ...
- poj 3669 Meteor Shower
Me ...
- POJ 3669 Meteor Shower BFS 水~
http://poj.org/problem?id=3669 题目大意: 一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达 ...
- poi 3669 meteor shower (bfs)
题目链接:http://poj.org/problem?id=3669 很基础的一道bfs的题,然而,我却mle了好多次,并且第二天才发现错在了哪里_(:з)∠)_ 写bfs或者dfs一定要记得对走过 ...
随机推荐
- python连续爬取多个网页的图片分别保存到不同的文件夹
python连续爬取多个网页的图片分别保存到不同的文件夹 作者:vpoet mail:vpoet_sir@163.com #coding:utf-8 import urllib import ur ...
- 在浏览器中输入Google.com并且按下回车之后发生了什么?
作者: skyline75489 来源: skyline75489的博客 发布时间: 2015-03-26 16:57 阅读: 4163 次 推荐: 23 原文链接 [收藏] ...
- ES6的模块化
在之前的 javascript 中一直是没有模块系统的,前辈们为了解决这些问题,提出了各种规范, 最主要的有CommonJS和AMD两种.前者用于服务器,后者用于浏览器.而 ES6 中提供了简单的模块 ...
- 转:Xshell显示找不到匹配的outgoing encryption算法怎么办
原文出处:http://www.xshellcn.com/xsh_column/suanfa-bpp.html 由用户反应在使用xshell和xftp连接debian 7时出现找不到匹配的outgoi ...
- ubuntu系统分区方案
一.各文件及文件夹的定义 /bin:bin是binary(二进制)的缩写.存放必要的命令 存放增加的用户程序. /bin分区,存放标准系统实用程序./boot:这里存放的是启动LINUX时使用的一些核 ...
- 【筛素数表证明】【O[n]】
void get_prime() { int cnt = 0; for (int i = 2; i < N; i++) { if (!tag[i]) p[cnt++] = i; for (int ...
- OA、CRM、ERP之间的区别和联系是什么?
我们假设你是某机械行业的销售,一切从今天你收到公司的邮件,去上海参加展会开始 因为 去展会 所有 首先 你打开 OA 登陆 填写出差申请表 送交主管审批 填表--审批--行政订票酒店 然后呢 你飞去上 ...
- java面对对象 关键字this super
this:this是指向对象本身的一个指针,成员函数内部指向当前类的对象 其实this主要要三种用法: 1.表示对当前对象的引用! 2.表示用类的成员变量,而非函数参数,注意在函数参数和成员变量同名是 ...
- android:padding和android:margin的区别
Android的Margin和Padding跟Html的是一样的.如下图所示:黄色部分为Padding,灰色部分为Margin. 通俗的理解: Padding 为内边框,指该控件内部内容,如文本/图片 ...
- HDU 1051 - Rightmost Digit
找循环 #include <iostream> #include <cmath> using namespace std; int t,m,p,q; long long n; ...