流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间。

对于每颗流星雨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的更多相关文章

  1. POJ 3669 Meteor Shower【BFS】

    POJ 3669 去看流星雨,不料流星掉下来会砸毁上下左右中五个点.每个流星掉下的位置和时间都不同,求能否活命,如果能活命,最短的逃跑时间是多少? 思路:对流星雨排序,然后将地图的每个点的值设为该点最 ...

  2. poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  3. POJ 3669 Meteor Shower (BFS+预处理)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  4. 题解报告:poj 3669 Meteor Shower(bfs)

    Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...

  5. POJ 3669 Meteor Shower(流星雨)

    POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS    Memory Limit: 65536K Description 题目描述 Bessie hears ...

  6. POJ 3669 Meteor Shower BFS求最小时间

    Meteor Shower Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31358   Accepted: 8064 De ...

  7. poj 3669 Meteor Shower

                                                                                                      Me ...

  8. POJ 3669 Meteor Shower BFS 水~

    http://poj.org/problem?id=3669 题目大意: 一个人从(0,0)出发,这个地方会落下陨石,当陨石落在(x,y)时,会把(x,y)这个地方和相邻的的四个地方破坏掉,求该人到达 ...

  9. poi 3669 meteor shower (bfs)

    题目链接:http://poj.org/problem?id=3669 很基础的一道bfs的题,然而,我却mle了好多次,并且第二天才发现错在了哪里_(:з)∠)_ 写bfs或者dfs一定要记得对走过 ...

随机推荐

  1. jQuery的入门与简介《思维导图》

    <初学者请各位高手指点指点> jQuery是继Prototype之后又一个优秀的JavaScript库,在JavaScript基础上我知道了jQuery拥有强大的选择器, 出色的DOM操作 ...

  2. Can you find it? 分类: 二分查找 2015-06-10 19:55 5人阅读 评论(0) 收藏

    Description Give you three sequences of numbers A, B, C, then we give you a number X. Now you need t ...

  3. FVANCOP/ChartNew.js

    FVANCOP/ChartNew.js FVANCOP/ChartNew.js

  4. GridBagLayout练习

    摘自http://blog.csdn.net/qq_18989901/article/details/52403737  GridBagLayout的用法 GridBagLayout是面板设计中最复杂 ...

  5. UGUI Button控件

    今天一起来学习下Button控件, Button控件其实是由Text,Button,Image组件形成的. 这里就简单介绍下Button组件 Interactable: 代表该组件是否进行交互, 我们 ...

  6. [Java Web]Struts2解决中文乱码问题

    1.设置struts的字符编码,能够在struts.xml中添加下面代码: <constant name="struts.i18n.encoding" value=" ...

  7. 《Qt编程的艺术》——5.1 手动布局

    在传统的GUI设计中,每个控件(Widget)都要手动地绑定在窗口之上的一个点上(也就是说,这个控件被指定成了给定GUI元素的父对象),同时还要指定这个控件的高度和宽度.作为所有图形元素的基础类,QW ...

  8. Hadoop中SequenceFile的使用

    1.对于某些应用而言,须要特殊的数据结构来存储自己的数据. 对于基于MapReduce的数据处理.将每一个二进制数据的大对象融入自己的文件里并不能实现非常高的可扩展性,针对上述情况,Hadoop开发了 ...

  9. log4.net 日志工具使用

    1. 在应用程序的相同目录下建立: winform :    程序名.exe.config          .(log4net程序,就log4net.exe.config) web:         ...

  10. CSS学习笔记——盒模型,块级元素和行内元素的区别和特性

    今天本来打算根据自己的计划进行前端自动化的学习的,无奈早上接到一个任务需求需要新增一个页面.自从因为工作需要转前端之后,自己的主要注意力几 乎都放在JavaScript上面了,对CSS和HTML这方面 ...