UVA-12264 Risk

Source: Internet
Author: User

Test instructions comparison pit, after moving the soldiers can not move again, or the sample will not be over ...

Minimum value maximum so the two-point answer, run network flow verification is feasible.

This topic focus on the building, in order to ensure that only move once, split, one into the point of an out point, to the point of nature can not be dispatched again.

An edge that does not have a capacity of 1 on the edge of the boundary means that at least one person is left, and the edge of the T on the border is set to mid.

Other Details:

Pay attention to the two points when the answer is L=mid+1,r=mid (l+r)/2 downward rounding,

L=mid,r=mid-1 (l+r)/2 rounding up, otherwise encountered such as R = l+1 judgment after the execution L = Mid this situation will die loop.

At first I wanted to reduce the flow of traffic no longer on the boundary by one, but it was quite similar to forcing the current position toward T by 1, in fact its 1 did not have to be provided by itself

, after moving the soldiers can not move again, then the flow can be reduced to the border, unless the movement after the soldiers can move again this is the right. Test Instructions Pit Ah ...

#include <bits/stdc++.h>using namespacestd;Const intMAXN = the<<1;intA[maxn],n;structedge{intv,cap,flow,nxt;}; Vector<Edge>edges;#definePB push_backintHEAD[MAXN];voidAddedge (intUintVintc) {edges. PB ({v,c,0, Head[u]}); Head[u]= Edges.size ()-1; Edges. PB ({u,0,0, Head[v]}); HEAD[V]= Edges.size ()-1;}Const intINF =0x3f3f3f3f;intS,T,CUR[MAXN],Q[MAXN],D[MAXN];BOOLBFs () {memset (d,0,sizeof(d)); intL =0, r =0; Q[r+ +] = S; D[s] =1;  while(r>l) {        intU = q[l++];  for(inti = Head[u]; ~i; i =edges[i].nxt) {Edge&e =Edges[i]; if(!D[E.V] && e.cap>E.flow) {D[E.V]= d[u]+1; Q[r++] =e.v; }        }    }    returnd[t];}intDfsintUinta) {    if(U = = t| |! AreturnA; intFlow =0, F;  for(int&i = Cur[u]; ~i; i =edges[i].nxt) {Edge&e =Edges[i]; if(D[E.V] = = d[u]+1&& (f = DFS (E.v,min (e.cap-e.flow,a))))  {Flow+ = f; A-=F; E.flow+ = f; edges[i^1].flow-=F; if(!a) Break; }    }    returnflow;}intMaxflow () {intFlow =0;  while(BFS ()) {memcpy (Cur,head,sizeof(head)); Flow+=DFS (S,inf); }    returnflow;} Vector<int>Change ;voidinit () {edges.clear ();    Change.clear (); memset (Head,-1,sizeof(head));}voidRebuildintcap) {     for(inti =0; I < edges.size (); i++) {Edges[i].flow=0; }     for(inti =0; I < change.size (); i++) {Edges[change[i]].cap=cap; }}intMain () {//freopen ("In.txt", "R", stdin);    intTest; scanf"%d",&Test);  while(test--) {scanf ("%d",&N);        Init (); S= n<<1; T = s|1; intL =1, r =0;  for(inti =0; I < n; i++) {scanf ("%d", a+i); R + =A[i]; }        CharSTR[MAXN]; intCNT =0, sum =0;  for(inti =0; I < n; i++) {scanf ("%s", str); if(!a[i])Continue; BOOLborder =false;  for(intj =0; J < N; J + +){                if(Str[j] = ='Y'){                    if(A[j]) Addedge (i,j+N,inf); ElseBorder=true;            }} Addedge (S,i,a[i]); Addedge (I,i+N,inf); if(border) CHANGE.PB (Edges.size ()), Addedge (I+n,t,0), cnt++; ElseAddedge (I+n,t,1), sum++; }        intmid;  for(; l < R; sum + mid*cnt = = Maxflow ()? l = Mid:r = mid-1) Mid= (l+r+1) >>1, rebuild (mid);//L = Mid. Rounding up L = mid+1 roundingprintf"%d\n", L); }    return 0;}

UVA-12264 Risk

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.