Exercises
The Divine question together ...
The sticking point here: http://hi.baidu.com/strongoier/item/0425f0e5814e010265db0095
Fractional planning can be seen here: http://blog.csdn.net/hhaile/article/details/8883652
Infinity Orzzzzz
Code: Real network Flow real egg hurts ...
1#include <cstdio>2 3#include <cstdlib>4 5#include <cmath>6 7#include <cstring>8 9#include <algorithm>Ten One#include <iostream> A -#include <vector> - the#include <map> - -#include <Set> - +#include <queue> - +#include <string> A at #defineINF 1000000000 - - #defineMAXN 200000+5 - - #defineMAXM 200000+5 - in #defineEPS 1e-10 - to #definell Long Long + - #definePA pair<int,int> the * #defineFor0 (i,n) for (int i=0;i<= (n); i++) $ Panax Notoginseng #defineFor1 (i,n) for (int i=1;i<= (n); i++) - the #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + A #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) the + #defineFor4 (i,x) for (int i=head[x],y;i;i=e[i].next) - $ #defineMoD 1000000007 $ - using namespacestd; - theInlineintRead () - Wuyi { the - intx=0, f=1;CharCh=GetChar (); Wu - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} About $ while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} - - returnx*F; - A } + intn,m,s,t,tot=1, head[maxn],cur[maxn],h[maxn],num[ -][ -]; the Doublemaxflow,a[ -][ -][3]; -queue<int>Q; $ structedge{intGo,next;Doublev;} E[MAXM]; theInlinevoidAddintXintYDoublev) the { theE[++tot]= (Edge) {y,head[x],v};head[x]=tot; theE[++tot]= (Edge) {X,head[y],0};head[y]=tot; - } in BOOLBFS () the { the for(inti=s;i<=t;i++) h[i]=-1; AboutQ.push (s); h[s]=0; the while(!q.empty ()) the { the intx=Q.front (); Q.pop (); + for(intI=head[x];i;i=e[i].next) - if(e[i].v>eps&&h[e[i].go]==-1) the {Bayih[e[i].go]=h[x]+1; Q.push (e[i].go); the } the } - returnh[t]!=-1; - } the DoubleDfsintXDoublef) the { the if(x==t)returnF; the DoubleTmp,used=0.0; - for(intI=cur[x];i;i=e[i].next) the if(e[i].v>eps&&h[e[i].go]==h[x]+1) the { theTmp=dfs (E[i].go,min (e[i].v,f-used));94e[i].v-=tmp;if(e[i].v>eps) cur[x]=i; thee[i^1].v+=tmp;used+=tmp; the if(Fabs (used-f) <eps)returnF; the }98 if(used<eps) h[x]=-1; About returnused; - }101 voiddinic ()102 {103maxflow=0.0;104 while(BFS ()) the {106 for(inti=s;i<=t;i++) cur[i]=head[i];maxflow+=DFS (s,inf);107 }108 }109 BOOLCheckDoublemid) the {111 Doubleret=0.0; theMemset (Head,0,sizeof(head)); tot=1;113For0 (i,n+1) For0 (j,m+1) the if(i&&i<n+1&&j&&j<m+1) Add (s,num[i][j],a[i][j][0]), ret+=a[i][j][0]; the ElseAdd (num[i][j],t,inf); theFor0 (i,n) For1 (j,m) Add (num[i][j],num[i+1][j],mid*a[i][j][1]), add (num[i+1][j],num[i][j],mid*a[i][j][1]);117For1 (i,n) for0 (j,m) Add (num[i][j],num[i][j+1],mid*a[i][j][2]), add (num[i][j+1],num[i][j],mid*a[i][j][2]);118 dinic ();119 returnret-maxflow>1e-9; - }121 122 intMain ()123 124 { the 126Freopen ("Input.txt","R", stdin);127 -Freopen ("output.txt","W", stdout);129 theN=read (); m=read ();131For0 (i,n+1) For0 (j,m+1) num[i][j]=++tot;s=0; t=++tot; theFor1 (i,n) For1 (j,m) a[i][j][0]=read ();133For0 (i,n) For1 (j,m) a[i][j][1]=read ();134For1 (i,n) for0 (j,m) a[i][j][2]=read ();135 DoubleL=0, r=n*m* -;136 while(r-l>1e-5)137 {138 DoubleMid= (L+R)/2;139 if(Check (mid)) L=mid;ElseR=mid; $ }141printf"%.3f\n", L);142 143 return 0;144 145}
View Code 3232: Enclosure game time limit:20 Sec Memory limit:128 MB
submit:498 solved:248
[Submit] [Status] DescriptionThe backyard of the Dzy home is a piece of land, consisting of n rows of M-columns, the dishes of the lattice are of certain value, and each unit length of the lattice line has a certain cost. Dzy like to take a walk in the field. He always departs from any lattice, walks along the grid until he returns to the starting point, and does not allow any intersecting or touching of the route that has been traversed (except the starting point) on the way. The total value of the lattice inside this closed route is V, and the sum of the costs on the route is C,dzy wondering what the maximum value of v/c is. InputThe first behavior is two positive integers of n,m. The next n lines, m nonnegative integers per line, represent the value of the corresponding lattice. The next n+1 line, m positive integers per line, represents the cost on all horizontal gridlines. next n rows, each line m+1 a positive integer, representing the cost on all vertical gridlines. (all data is entered in order from left to right, top to bottom, see examples and maps)OutputThe output line contains only one number, which represents the largest v/c and retains 3 decimal places. Sample Input3 4
1 3 3 3
1 3 1 1
3 3 1 0
100 1 1 1
97 96 1 1
1 93 92 92
1 1 90 90
98 1 99) 99 1
95 1 1) 1 94
1 91 1) 1 89
Sample Output1.286HINT
Source
JCVB offers
BZOJ3232: Enclosure Game