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