Pit point:
1. Array open, 0-300 is Meteor fall range
2.maps[tx][ty] = min (maps[tx][ty],t); Meteor two times drop the same place take time small
Idea: The value on the maps[][] graph as the time at which the point cannot walk (judging 5 directions according to the Meteor Fall time)
1#include <cstdio>2#include <cstring>3#include <queue>4#include <iostream>5 using namespacestd;6 7 intmaps[ -][ -];8 intDx[] = {-1,0,0,0,1};9 intDy[] = {0,-1,0,1,0};Ten BOOLvis[ -][ -]; One structnode{ A intX,y,step; -Node (intXintYintstep): X (x), Y (y), step (step) {} - }; theQueue<node>que; - BOOLOkintXintYintStep) { - if(! (x>=0&& y>=0&& x<= -& y <= -))return false; - if(Vis[x][y])return false; + if(step >= Maps[x][y])return false; - return true; + } A at BOOLBFs () { -Que.push (Node (0,0,0)); -vis[0][0] =true; - while(!Que.empty ()) { -Node tmp =Que.front (); Que.pop (); - intx = tmp.x, y = tmp.y, step =Tmp.step; in if(Maps[x][y] = =0x7f7f7f7f){ -printf"%d\n", step); to return true; + } - for(inti =0; I <5; i + +){ the intNEWX = x +Dx[i]; * intNewy = y +Dy[i]; $ if(OK (newx,newy,step+1)){Panax NotoginsengVis[newx][newy] =true; -Que.push (Node (newx,newy,step+1)); the } + } A } the return false; + } - $ intMain () { $ intN; - while(SCANF ("%d", &n)! = EOF &&N) { - while(!que.empty ()) Que.pop (); thememset (Vis,false,sizeof(Vis)); -memset (Maps,0x7f7f7f7f,sizeof(maps));Wuyi for(inti =0; I < n; i + +){ the intx,y,t; -scanf"%d%d%d",&x,&y,&t); Wu for(inti =0; I <5; i + +){ - inttx = x +Dx[i]; About intTy = y +Dy[i]; $ if(tx>=0&& ty>=0&& tx<= -& Ty <= -) -Maps[tx][ty] =min (maps[tx][ty],t); - } - } A if(maps[0][0] ==0) printf ("-1\n"); + Else if(!bfs ()) printf ("-1\n"); the } - $ return 0; the}
POJ 3669 Meteor shower (BFS)