POJ 3669 Meteor Shower

Source: Internet
Author: User
Tags define local

BFS is good, take the earliest destruction time.

For a set of data, initialization is not, directly with the dist[][] state of the weight.

#include <cstdio>#include<iostream>#include<string>#include<cstring>#include<queue>#include<vector>#include<stack>#include<vector>#include<map>#include<Set>#include<algorithm>using namespacestd;#definePB push_back#defineMP Make_pair#defineFi first#defineSe Second#definePS push#defineCER (x) cout<< #x << ' = ' <<endltypedefLong Longll;Const intINF =0x3f3f3f3f;//const int MINF = -1-inf;//0xc0c0c0c0;#defineREP0 (i,n) for (int i = 0; i < n; i++)#defineREP1 (i,n) for (int i = 1; I <= n; i++)#defineDWN (i,n) for (int i = n; i > 0; i--)#defineDwn_ (i,n) for (int i = n; I >= 0; i--)#defineREP (i,s,e) for (int i = s; i < E; i++)#defineRep_ (i,s,e) for (int i = s; I <= e; i++)#defineCLR (a,v) memset (A,v,sizeof (a))#definepara int o = 1, int l = 1,int r = N#defineLo (o<<1)#defineRO (o<<1|1)#defineTEMP int mid = (l+r) >>1;#defineLSN lo, L, mid#defineRSN ro, mid+1, R#defineINSD QL&LT;=L&AMP;&AMP;R&LT;=QRinlineintRead () {intRetCharC while(c = GetChar (),c<'0'|| C>'9'); RET= C'0';  while(c = GetChar (), c>='0'&&c<='9') ret = ret*Ten+ C'0'; returnret;} Inlineintreads () {intRetCharC while(c = GetChar (), C! ='-'&& c<'0'|| C>'9'); BOOLSign = c = ='-'; RET= sign?0: C-'0';  while(c = GetChar (), c>='0'&&c<='9') ret = ret*Ten+ C'0'; returnsign?-Ret:ret;}Const intMAXN =305;intG[MAXN][MAXN];intD[MAXN][MAXN];Const intMxT =1001; typedef pair<int,int>Node;Const intDx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};BOOLValidintXinty) {    returnx>=0&&x<maxn&&y>=0&&y<MAXN;}intBFs () {Queue<Node>Q; Q.push (Node (0,0)); d[0][0] =1;  while(Q.size ()) {Node U=Q.front (); Q.pop (); if(g[u.fi][u.se] > MxT)returnd[u.fi][u.se]-1; intStep =d[u.fi][u.se];  for(intK =0; K <4; k++){            intNX = U.fi+dx[k], NY = u.se+Dy[k]; if(Valid (Nx,ny) &&!d[nx][ny] && Step <G[nx][ny]) {D[nx][ny]= step+1;            Q.push (Node (Nx,ny)); }        }    }    return-1;}//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endif    intM =read (); Memset (g,0x3f,sizeof(g));  for(intI:j; i--;){        intx = Read (), y =read (); intt =read ();  for(intK =0; K <4; k++){            intNX = X+dx[k], NY = y+Dy[k]; if(valid (Nx,ny)) {G[nx][ny]=min (g[nx][ny],t); }} G[x][y]=min (g[x][y],t); } printf ("%d\n", BFS ()); return 0;}//freopen ("OutStd.txt", "w", stdout);

POJ 3669 Meteor Shower

Related Article

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.