Meteor Shower
来源:互联网 发布:超次元矩阵闪退 编辑:程序博客网 时间:2024/06/07 01:08
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 (1 ≤ M ≤ 50,000) will strike, with meteor i will striking point (Xi, Yi) (0 ≤ Xi ≤ 300; 0 ≤ Yi ≤ 300) at time Ti (0 ≤ Ti ≤ 1,000). Each meteor destroys the point that it strikes and also the four rectilinearly adjacent lattice points.
Bessie leaves the origin at time 0 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 4) 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 1: A single integer: M
* Lines 2..M+1: Line i+1 contains three space-separated integers: Xi, Yi, and Ti
Output
* Line 1: The minimum time it takes Bessie to get to a safe place or -1 if it is impossible.
Sample Input
40 0 22 1 21 1 20 3 5
Sample Output
5
这道B题,我就操了,整了那么久。这道题题意就是一个妹子的家乡要被流星雨袭击,妹子家住在原点坐标处,地图只包括第一象限
,给出流行下落的位置以及时间,流行还会毁坏它附近(上下左右)的位置,问你妹子走最少几步就能到达安全区。
这道题得进行预处理,也就是说先把流行坠落的位置处以及他的周围标记上时间,如果你在大于这个时间的时候到达这。那么肯定是不行的。
我这里有一个注意点需要记住,memset初始化二维数组只能是0跟-1,但十六进制数也是可以的,实在不行就用for循环。
另外我这里有一个点一直过不了差点气死我,就是你广搜如果搜不到安全区域呢,那么不就得输出-1,可我却没有进行处理。
好好记住这个教训。
#include<iostream>#include<stdio.h>#include<queue>#include<string.h>#include<stdlib.h>#define INF 99999using namespace std;struct node{int x;int y;int step;};queue<node> Q;int map[512][512];int book[512][512];int next[5][2]={{0,0},{1,0},{-1,0},{0,1},{0,-1}};int M,most=0,flag=0;void BFS();int main(){int i,j,xx,yy,tt,nx,ny;cin>>M;//memset(map,0x7F,sizeof(map));for(i=0;i<512;i++)for(j=0;j<512;j++)map[i][j]=INF;memset(book,0,sizeof(book));for(i=0;i<M;i++){scanf("%d %d %d",&xx,&yy,&tt);//cout<<"tt="<<tt<<endl;most=max(most,tt);for(j=0;j<5;j++){nx=xx+next[j][0];ny=yy+next[j][1];if(nx<0 || ny<0) continue;//printf("nx=%d ny=%d map=%d\n",nx,ny,map[nx][ny]);if(map[nx][ny]>tt){map[nx][ny]=tt;//cout<<map[nx][ny]<<endl;}}}book[0][0]=1;if(map[0][0]==0){printf("-1\n");}else{BFS();if(flag==0)printf("-1\n");}return 0;}void BFS(){struct node start,temp;int i,j;start.x=0;start.y=0;start.step=0;Q.push(start);while(!Q.empty()){start=Q.front();Q.pop();for(i=1;i<5;i++){temp=start;temp.x=start.x+next[i][0];temp.y=start.y+next[i][1];temp.step++;if(temp.x<0 || temp.y<0) continue;//out<<map[temp.x][temp.y]<<endl;if(map[temp.x][temp.y]>temp.step && book[temp.x][temp.y]==0){//puts("jdd");book[temp.x][temp.y]=1;if(map[temp.x][temp.y]>most){printf("%d\n",temp.step);flag=1;return ;}Q.push(temp);}}}}
- Meteor Shower
- Meteor Shower
- Meteor Shower
- 流星雨 meteor shower
- POJ3669 Meteor Shower BFS
- POJ 3669 - Meteor Shower
- POJ 3699 Meteor Shower
- poj 3669 Meteor Shower
- poj 3669 Meteor Shower
- POJ-3669-Meteor Shower
- POJ 3669 Meteor Shower
- poj 3669Meteor Shower
- POJ-3669 Meteor Shower
- poj3669 Meteor Shower BFS
- POJ3669 Meteor Shower(BFS)
- Meteor Shower(3669)
- Poj 3699 Meteor Shower
- POJ3669 Meteor Shower 【BFS】
- TCP重传的次数和间隔时间
- 亚马逊 AWS 免费云服务操作流程
- HashSet是如何检查重复?
- 51nod 1202 子序列个数 (组合数学 +动态规划)
- hihoCoder#1032 : 最长回文子串
- Meteor Shower
- 主线程执行10,子线程执行10.交替执行50次结束
- Android 签名混淆-多渠道打包
- 二叉树操作总结
- C++ explicit关键字详解
- 自学第二遍堆抽象类的理解:
- Spring集成Camel
- View的基本位置参数介绍
- 近期有点忙