"POJ 3669 Meteor shower" simple BFS

Source: Internet
Author: User

Meteor showers hit the Earth (the first quadrant of planar Cartesian coordinates), asking for the minimum time to reach the safe zone.

For each meteor shower I, at ti time Impact (Xi,yi) point, while causing (xi,yi) and up and down adjacent points in ti after the moment (including T) can no longer pass (blocked). The safe zone is a point that will never be blocked.

Simple BFS, start WA in the upper limit of the plane space as 300*300, but according to the topic, this is only the range of meteor shower impact. The actual available space theoretically no upper limit, but the analysis is available, the nearest security zone from the origin must be within the range of (302,302), so the array should be opened at least as 303*303.

Later WA in the g[0][0]==1 of the situation also attributed to the non-solution. This is not to know the meaning of pretreatment ...

1#include <cstdio>2#include <cstring>3#include <queue>4#include <algorithm>5 using namespacestd;6 7 Const intinf=10000;8 Const intmax_n=302;//meteor showers fall Within (300,300), so the nearest safety point must be within (302,302)9 intm;Ten intg[max_n+1][max_n+1]; One intdx[]={0,0,1,-1},dy[]={1,-1,0,0}; A intvis[max_n+1][max_n+1]; -  - structNode the { -     intX,y,time; - Node () {} -Node (intXxintYyintt): X (xx), Y (yy), time (t) {} + }; -  + intInsideintXinty) A { at     if(x<0|| y<0|| max_n<x| | Max_n<y)return 0; -     Else return 1; - } -  - intBFS () - { inmemset (Vis,0,sizeof(Vis)); -     if(g[0][0]==inf)return 0; to     if(g[0][0]==0)return-1;//when g[0][0]==1, does not mean no hope to escape ...  +     //because the G array is preprocessed, the effect of each meteor shower is expressed as the block time of each point -Queue<node>que; theQue.push (Node (0,0,0)); *vis[0][0]=1; $      while(!que.empty ())Panax Notoginseng     { -Node cur=Que.front (); the Que.pop (); +         if(G[cur.x][cur.y]==inf)returnCur.time; A          for(intI=0;i<4; i++) the         { +             intnx=cur.x+Dx[i]; -             intny=cur.y+Dy[i]; $             if(!inside (Nx,ny))Continue; $             if(Vis[nx][ny])Continue; -             if(g[nx][ny]<=cur.time+1)Continue; -Que.push (Node (nx,ny,cur.time+1)); thevis[nx][ny]=1; -         }Wuyi     } the     return-1; - } Wu  - intMain () About { $Freopen ("3669.txt","R", stdin); -scanf"%d",&m); -      for(intI=0; i<=max_n;i++) -          for(intj=0; j<=max_n;j++) Ag[i][j]=INF; +      for(intI=0; i<m;i++) the     { -         intx,y,t; $scanf"%d%d%d",&x,&y,&t); theg[x][y]=min (t,g[x][y]); the          for(intI=0;i<4; i++) the{//preprocessing the G array to the earliest blocking time for each point the             intnx=x+Dx[i]; -             intny=y+Dy[i]; in             if(!inside (Nx,ny))Continue; theg[nx][ny]=min (T,g[nx][ny]); the         } About     } theprintf"%d\n", BFS ()); the     return 0; the}

Or consider the problem is not comprehensive not clear ah ... More questions, more summaries.

"POJ 3669 Meteor shower" simple 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.