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

对于每颗流星雨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. WPF & ArcGIS Engine三维开发入门攻略

    原文 http://www.cnblogs.com/Realh/archive/2010/12/14/1906112.html 前些日子在做ESRI的开发大赛,从刚开始接触ArcGIS Engine( ...

  2. Linux下ld搜索问题:ld: cannot find -l"XX"

    ld命令行工具(链接库的一个工具)的搜索路径是-L指定的,库名是-l指定的. 比如: ld -L[dir] -l[mylib] --verbose 以上我用可视化的方法显示ld的搜索路径,其结果是居然 ...

  3. Linux系统编程(23)——信号的阻塞

    实际执行信号的处理动作称为信号递达(Delivery),信号从产生到递达之间的状态,称为信号未决(Pending).进程可以选择阻塞(Block)某个信号.被阻塞的信号产生时将保持在未决状态,直到进程 ...

  4. windows phone中,将crash report记录下来,写入文件,方便分析

    APP出现crash(崩溃)总是不能忍的 当我们连接调试器调试的时候,发现每当APP崩溃的时候 程序都会走到App.xaml.cs中的 // Code to execute on Unhandled ...

  5. 2.9 Model Selection and the Bias–Variance Tradeoff

    结论 模型复杂度↑Bias↓Variance↓ 例子 $y_i=f(x_i)+\epsilon_i,E(\epsilon_i)=0,Var(\epsilon_i)=\sigma^2$ 使用knn做预测 ...

  6. hdu1172猜数字(暴力枚举)

    猜数字 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  7. bash及其特性(笔记)

    bash及其特性:shell: 外壳GUI:Gnome, KDE, XfceCLI: sh, csh, ksh, bash, tcsh, zsh root, student程序:进程 进程:在每个进程 ...

  8. 物理机与虚拟机IP互ping通,而互ping主机名不通

    问题描述:虚拟机信息:VMware-workstation 10安装RHEL5.8操作系统.hostname:rhel201.com IP:192.168.1.201 物理机系统:windows 7主 ...

  9. 新生赛(2) problem 2 丁磊养猪

    Problem B Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  10. Mongodb中Sharding集群

    随着mongodb数据量的增多,可能会达到单个节点的存储能力限制,以及application较大的访问量也会导致单个节点无法承担,所以此时需要构建集群环境,并通过sharding方案将整个数据集拆分成 ...