BZOJ1930 [Shoi2003]pacman eats peas

Source: Internet
Author: User

Shoi had such a ghost problem? Kneeling

First, we can think of the cost of network flow, find a flow of 2 of the maximum cost flow can be, the question is how to build a map

Because the point is to gain, and only once the proceeds, so consider the split, it may be possible to set a point P split into points P1 and out point P2

Then P1-P2 with the edge flow of 1, the cost is 1, and then the edge traffic is 1, the cost is 0;s to P1 with the edge of 1, the cost is 0;p2 to the t edge, the flow is 1, the cost is 0

If p can reach Q, then P2-Q1 with a flow of 2, the cost is 0

Then you will find too many sides ... Optimization?

If I can reach the j,j can reach K, then I do not to the K-side, so it is a monotone problem, the point of the x-axis sorting, and then the y-axis monotonically increased in the way of the edge.

1 /**************************************************************2 problem:19303 User:rausen4 language:c++5 result:accepted6 time:192 Ms7 memory:63416 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <algorithm> A   - using namespacestd; - Const intN = -; the Const intM = 4e6 +5; - Const intINF =1e9; -   -InlineintRead () { +     intx =0; -     CharCH =GetChar (); +      while(Ch <'0'||'9'<ch) ACH =GetChar (); at      while('0'<= CH && Ch <='9') { -x = x *Ten+ CH-'0'; -CH =GetChar (); -     } -     returnx; - } in   - structPoint { to     intx, y; +       -Inlinevoidread_in () { thex = Read (), y =read (); *     } $InlineBOOL operator< (ConstPoint &p)Const {Panax Notoginseng         returnx = = p.x? Y < P.y:x <p.x; -     } the } P[n]; +   A structEdges { the     intnext, to, F, cost; + edges () {} -Edgesint_n,int_t,int_f,int_c): Next (_n), to (_t), F (_f), cost (_c) {} $ } E[m]; $   - intN, S, S1, T; - intFirst[n <<1], tot =1; the intA[n]; - intD[n <<1], G[n <<1], Q[n <<1], Vis[n <<1];Wuyi BOOLV[n <<1]; the   -InlinevoidAdd_edges (intXintYintFintc) { WuE[++tot] = Edges (first[x], y, F, c), first[x] =tot; -E[++tot] = Edges (First[y], X,0,-C), first[y] =tot; About } $    -InlineintCalc () { -     intFlow =inf, x; -      for(x = g[t]; x = g[e[x ^1].to]) AFlow =min (flow, e[x].f); +      for(x = g[t]; x = g[e[x ^1].to]) theE[X].F-= flow, e[x ^1].F + =flow; -     returnflow; $ } the   the #defineY e[x].to the BOOLSPFA () { the     intx, now, L, R; -      for(x =1; x <= S1; ++x) inD[X] =inf; theD[s] =0, v[s] =1, q[0] =S; the      for(L = r =0; L! = (R +1) %N;) { Aboutnow = Q[l], ++l%=N; the          for(x = First[now]; x; x =E[x].next) { the             if(D[now] + e[x].cost < D[y] &&e[x].f) { theD[y] = D[now] + e[x].cost, g[y] =x; +                 if(!V[y]) { -V[y] =1; the                     if(D[y] <D[q[l]])Bayiq[(L + = N-1)%= N] =y; the                     ElseQ[++r%= N] =y; the                 } -             } -         } theV[now] =0; the     } the     returnD[T]! =inf; the } - #undefY the   theInlineintWork () { the     intres =0;94      while(SPFA ()) theRes + = Calc () *D[t]; the     returnRes; the }98   About #defineP1 (i) (I << 1)-1 - #defineP2 (i) (I << 1)101 intMain () {102     intI, J, TMP;103n = Read (), S = n *2+1, T = S +1, S1 = T +1;104      for(i =1; I <= N; ++i) the p[i].read_in ();106Sort (p +1, p + n +1);107      for(i =1; I <= N; ++i) {108A[i] = P[I].Y, TMP =-1;109Add_edges (S1, p1 (i),1,0), Add_edges (P2 (i), T,1,0); theAdd_edges (P1 (i), p2 (i),1, -1), Add_edges (P1 (i), p2 (i),1,0);111          for(j = i-1; J --j) the             if(A[j] <= a[i] && A[j] >tmp)113TMP = A[j], Add_edges (P2 (j), p1 (i),2,0); the     } theAdd_edges (S, S1,2,0); theprintf"%d\n", -Work ());117     return 0;118}
View Code

BZOJ1930 [Shoi2003]pacman eats peas

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.