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

对于每颗流星雨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. shell字符串

    字符串是shell编程中最常用最有用的数据类型(除了数字和字符串,也没啥其它类型好用了),字符串可以用单引号,也可以用双引号,也可以不用引号.单双引号的区别跟PHP类似. 单引号 str='this ...

  2. iOS开发之property属性介绍

    大家都知道@property和@synthesize可以自动生成某个类成员变量的存取方法,但可能对property中的一些属性不是很了解,网上的一些介绍有的不是很正确,感觉会误导新手,于是准备详细介绍 ...

  3. POJ1988 并查集的使用

    Cube Stacking Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 21157   Accepted: 7395 Ca ...

  4. 关闭ubuntu apport

    apport就是ubuntu上的"crash report"服务,就是当有程序崩溃时弹出的那个发送error report的程序: 个人觉得此功能无用,本着给我的老本子节省资源的思 ...

  5. 什么是FastCGI?

    什么是FastCGI? PHP的FastCGI使你的所有php应用软件通过mod_fastci运行,而不是mod_phpsusexec.FastCGI应用速度很快 是因为他们持久稳定.不必对每一个请求 ...

  6. Python3.X与Python2.x的区别

    一张图说明Python2.x与Python3.x的不同. Python3.x默认使用Unicode编码.支持中文. 更多介绍请看:https://segmentfault.com/a/11900000 ...

  7. 查看Java包源码

  8. Unity 获取服务器时间 HTTP请求方式

    在写每日签到的时候,我居然使用的是本地时间...被项目经理笑哭了...., 如果你在写单机游戏,没有游戏服务器,但又不想使用本地时间,就可以采用下面方法. 方法总结: 1. 使用HTTP请求获取服务器 ...

  9. 棋盘覆盖(大数阶乘,大数相除 + java)

    棋盘覆盖 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 在一个2k×2k(1<=k<=100)的棋盘中恰有一方格被覆盖,如图1(k=2时),现用一缺角的 ...

  10. ModelAndView解析

    查看spring的帮助文档得到下面信息: org.springframework.web.servlet Class ModelAndViewjava.lang.Object org.springfr ...