BZOJ1736 [Usaco2005 jan]the Wedding Juicer The juice extractor of the wedding

Source: Internet
Author: User

From the outside 1.1 points to the inside expansion (FloodFill), each time to find the smallest point, calculate its contribution to the answer is good ...

If you find the smallest point, just PQ.

1 /**************************************************************2 problem:17363 User:rausen4 language:c++5 result:accepted6 time:196 Ms7 memory:2116 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <queue> A   - using namespacestd; -typedefLong Longll; the Const intN =305; - Const intDx[] = {0,0,1, -1}; - Const intDy[] = {1, -1,0,0}; -   +Inlineintread (); -   + structData { A     intx, Y, H; atDataint_x =0,int_y =0,int_h =0): X (_x), Y (_y), H (_h) {} -       -InlineBOOL operator< (ConstData &d)Const {    -         returnH >d.h; -     } - }; in   - intN, M; to intMp[n][n], v[n][n]; +Priority_queue <data>h; -   the inline ll work () { *ll res =0; $     intx, y, K;Panax Notoginseng data now; -      while(!H.empty ()) { thenow =h.top (), H.pop (); +          for(k =0; K <4; ++k) { Ax = now.x + dx[k], y = now.y +Dy[k]; the             if(x <=0|| Y <=0|| X > N | | Y > M | | V[x][y])Continue; +V[x][y] =1; -             if(Mp[x][y] <now.h) $Res + = Now.h-mp[x][y], mp[x][y] =now.h; $ H.push (data (x, Y, mp[x][y])); -         } -     } the     returnRes; - }Wuyi   the intMain () { -     intI, J; Wum = read (), n =read (); -      for(i =1; I <= N; ++i) About          for(j =1; J <= M; ++J) Mp[i][j] =read (); $      for(i =1; I <= N; ++i) -          for(j =1; J <= M; ++j) -             if(i = =1|| j = =1|| i = = N | | j = =m) -H.push (Data (i, J, Mp[i][j])), v[i][j] =1; Aprintf"%lld\n", work ()); +     return 0; the } -   $InlineintRead () { the     Static intx; the     Static Charch; thex =0, ch =GetChar (); the      while(Ch <'0'||'9'<ch) -CH =GetChar (); in      while('0'<= CH && Ch <='9') { thex = x *Ten+ CH-'0'; theCH =GetChar (); About     } the     returnx; the}
View Code

BZOJ1736 [Usaco2005 jan]the Wedding Juicer The juice extractor of the wedding

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.