BZOJ3393 [Usaco2009 Jan]laserphones Laser Communication

Source: Internet
Author: User

For the first time know. Originally SPFA can also write like this ... With PQ ...

Only need to directly seek the inflection point, the data small want how to engage in how to do

(Say how so bare the shortest short-circuit can not write out 233)

1 /**************************************************************2 problem:33933 User:rausen4 language:c++5 result:accepted6 time:36 Ms7 memory:1156 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <cstring> A#include <algorithm> -#include <queue> -   the using namespacestd; - Const intdx[4] = {0,1,0, -1}; - Const intdy[4] = {1,0, -1,0}; - Const intN = the; + Const intINF = (int) 1e9; -   + structData { A     intx, y, to, dis; at data () {} -Dataint_x,int_y,int_t,int_d): X (_x), Y (_y), to (_t), dis (_d) {} -       -InlineBOOL operator< (ConstData &b)Const { -         returnDis >B.dis; -     } in }; -   to intN, m, ans; + intSX, SY, ex, EY; - intdis[n][n][4], w[n][n]; thePriority_queue <data>Q; *   $InlineBOOL inch(intXinty) {Panax Notoginseng     return 1<= x && x <= n &&1<= y && y <=m; - } the   + intMain () { A     intI, J; the     Charch; +scanf"%d%d", &m, &n); -      for(i =1; I <= N; ++i) $          for(j =1; J <= M; ++j) { $CH =GetChar (); -          while(ch! ='C'&& ch! ='.'&& ch! ='*') -CH =GetChar (); the         if(ch = ='*') W[i][j] =1; -         if(ch = ='C')Wuyi             if(!SX) SX = i, sy =J; the             Elseex = i, EY =J; -     } Wumemset (DIS,127/3,sizeof(DIS)); -      for(i =0; I <4; ++i) { AboutQ.push (Data (SX, SY, I,0)); $Dis[sx][sy][i] =0; -     } -       -     intx, y, K, X1, y1; A      while(!Q.empty ()) { +X1 = x = Q.top (). x, y1 = y = Q.top (). Y, k =Q.top (). to; the          while(inch(x1 + = Dx[k], y1 + dy[k]) &&!w[x1][y1] && dis[x1][y1][k] >Dis[x][y][k]) { -DIS[X1][Y1][K] =Dis[x][y][k]; $ Q.push (Data (x1, y1, K, dis[x][y][k])); the         } the          for(i =0; I <4; ++i) the             if(Dis[x][y][i] > q.top (). Dis +1) { theDis[x][y][i] = q.top (). Dis +1; - Q.push (data (x, Y, I, dis[x][y][i])); in             } the Q.pop (); the     } About      for(i =0, ans = inf; I <4; ++i) theAns =min (ans, dis[ex][ey][i]); theprintf"%d\n", ans); the     return 0; +}
View Code

BZOJ3393 [Usaco2009 Jan]laserphones Laser Communication

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.