POJ 3669 Meteor Shower
2018-02-03 14:30
211 查看
Meteor Shower
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
Sample Output
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions:23249 | Accepted: 6044 |
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
4 0 0 2 2 1 2 1 1 2 0 3 5
Sample Output
5
本来设了右下边界为300,wa了一次,后来一想其实只要 逃到301以外的地方就算成功了,没必要设边界。 #include<cstdio> #include<queue> #include<string.h> #include<algorithm> #define INF 0x3f3f3f3f int a[333][333],d[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; bool mp[333][333]; using namespace std; struct node { int x,y,time; }; queue<node>P; int main() { memset(a,INF,sizeof(a)); memset(mp,0,sizeof(mp)); int m;scanf("%d",&m); while(m--) { int x,y,z;scanf("%d%d%d",&x,&y,&z); a[x][y]=min(a[x][y],z); for(int i=0;i<4;i++) { int xx=x+d[i][0],yy=y+d[i][1]; a[xx][yy]=min(a[xx][yy],z); } } if(a[0][0]==0) { printf("-1\n"); return 0; } node r;r.x=0,r.y=0,r.time=0;mp[0][0]=1; P.push(r); bool bb=0; while(!P.empty()) { r=P.front();P.pop(); for(int i=0;i<4;i++) { node e;e.x=r.x+d[i][0],e.y=r.y+d[i][1]; e.time=r.time+1; if(e.x<0||e.y<0)continue; if(a[e.x][e.y]==INF) { bb=1;printf("%d\n",e.time); break; } if(e.time<a[e.x][e.y]&&!mp[e.x][e.y]) { P.push(e); mp[e.x][e.y]=1; } } if(bb)break; } if(!bb)printf("-1\n"); return 0; }
相关文章推荐
- poj 3669 Meteor Shower(BFS)
- poj-3669-Meteor Shower
- POJ 3669 Meteor Shower
- POJ 3669 Meteor Shower
- poj 3669 Meteor Shower
- POJ 3669 Meteor Shower(预处理 + BFS)
- POJ3669——Meteor Shower(BFS)
- poj_3669_Meteor Shower(BFS+预处理)
- POJ 3669 Meteor Shower 普通BFS
- POJ 3669 Meteor Shower(BFS)
- poj 3669 Meteor Shower
- poj 3669 Meteor Shower
- POJ-3669--Meteor Shower---BFS广搜
- [POJ](3669)Meteor Shower ---- bfs+预处理
- Meteor Shower(POJ-3669)
- [POJ] 3669 Meteor Shower [BFS]
- bfs_poj_3669_Meteor Shower
- BFS搜索:POJ No 3669 Meteor Shower
- POJ 3669 Meteor Shower
- poj 3669 Meteor Shower(广度优先搜索)