title : http://www.lydsy.com/JudgeOnline/problem.php?id=1611
1611: [Usaco2008 feb]meteor Shower meteor shower
Time Limit:5 Sec Memory limit:64 MB
submit:1272 solved:557
[Submit] [Status] [Discuss]
Description
Last year, we suffered from the N-year frozen disaster in Hunan, now Lotus Brothers heard another shocking news: A meteor shower is about to attack the whole PA, because the meteor volume is too large, they can not be burned before hitting the ground, then it will hit all the things caused a devastating blow. Naturally, Lotus Brothers began to worry about their own safety problems. In the name of the bully to in the sportsman, he must be hit by a meteor before the arrival of a safe place (that is, a piece will not be hit by any meteor land). If the PA in a right-angled coordinate system, Lotus Brothers now position is the origin, and, Lotus Brothers can not embark on a meteor smashed land. According to the forecast, there are a total of M meteor (1 <= m <= 50,000) will fall in the PA, where the first meteor will be at the moment t_i (0 <= t_i <= 1,000) smashed in coordinates (x_i, y_i) (0 <= x_i <= 3 00;0 <= y_i <= 300) in the lattice. The power of the meteor will be the lattice in which it is located, and the surrounding 4 adjacent lattice into a scorched earth, of course, Lotus Brothers can no longer walk on these squares. Brother Furong at the moment 0 began to act, it can only in the first quadrant, parallel to the Axis action, every 1 moments, she can move to the adjacent (usually 4) lattice of any one, of course, the target lattice will not be burnt. If a lattice is in the moment T is hit or burnt by a meteor, then brother Furong can only appear in this lattice at the moment before T. Please calculate how long it will take at least to get to a safe grid.
Input
- Line 1th: 1 positive integers: M * 2nd. M+1 Line: section i+1 behavior 3 integers separated by spaces: x_i,y_i, and T_i
Output
Output 1 integers, that is, Lotus brother to escape the minimum time spent. If brother Furong can't survive a meteor shower anyway, output-1
Sample Input
4
0 0 2
2 1 2
1 1 2
0 3 5
Input Description:
一共有4颗流星将坠落在霸中,它们落地点的坐标分别是(0, 0),(2, 1),(1, 1)
and (0, 3), the time is 2,2,2,5 respectively.
Sample Output
5
HINT
Ideas :
Record the time of destruction; BFs to no-hurt point output;
Code :
#include <iostream>#include <stdio.h>#include <string.h>#include <queue>using namespace STD;intt[309][309];intd[309][309];structnode{intx, y; NodeintXxintyy) {x=xx,y=yy; }}; queue<node>QintNintdx[5]={0,-1,1,0,0};intdy[5]={0,0,0,1,-1};voidSolve () {if(t[0][0]==9999999) {printf("0\n");return; }if(t[0][0]==0) {printf(" -1\n");return; } d[0][0]=0; Q.push (Node (0,0)); while(!q.empty ()) {node Now=q.front (); Q.pop (); for(intI=1; i<=4; i++) {intTx=now.x+dx[i];intTy=now.y+dy[i];if(tx>=0&&tx<=301&&ty>=0&&ty<=301&&d[tx][ty]==9999999&&t[tx][ty]>d[now.x][now.y]+1) {d[tx][ty]=d[now.x][now.y]+1; Q.push (Node (tx,ty));if(t[tx][ty]==9999999) {printf("%d\n", D[tx][ty]);return; } } } }printf(" -1\n");}intAA,BB,CC;intMain () {scanf("%d", &n); for(intI=0; i<=301; i++) for(intj=0; j<=301; j + +) {t[i][j]=9999999; d[i][j]=9999999; } for(intI=1; i<=n;i++) {scanf("%d%d%d", &AA,&BB,&CC); for(intI=0;i<5; i++) {intTX=DX[I]+AA;intTY=DY[I]+BB;if(tx>=0&&ty>=0) T[tx][ty]=min (Cc,t[tx][ty]); }} solve ();}
"Bzoj 1611" [Usaco2008 feb]meteor shower meteor shower BFs