POJ 3669 Meteor shower (BFS)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.