Surprised, Tle half a day to find floating point arithmetic is to add esp, really learned.
Topic Link Https://www.nowcoder.com/acm/contest/207/G
Test instructions is to give you n points, each point has SI personal and bi food backpack, then the M-side, each side has an electric shock probability pi, the first person through this side will not electric shock, ask you to let everyone eat meal of the minimum electric shock probability.
Method: If the Si>bi connects 0 to I capacity for si-bi, the cost is 0, otherwise the connection I to n+1, the capacity is Bi-si, the cost is 0
Then split each line into two, a capacity of 1, the cost is 0, a capacity of c-1, the cost of-log (1-PI)
Because the last to output all probability of the product of the minimum value, take the logarithm into a negative number, plus the minimum change after the maximum, so then the probability of inversion into (1-PI)
Run one side the shortest output 1-exp (-ans) can be
#include <bits/stdc++.h>#defineESP 1e-7using namespacestd;Const intmaxn=205;Const intinf=0x3fffffff;structedge{int from, To,cap,flow; DoubleCost ;};structmcmf{intn,m,s,t; Vector<Edge>edges; Vector<int>G[MAXN]; intINQ[MAXN]; DoubleD[MAXN]; intP[MAXN]; intA[MAXN]; voidInitintN) { This->n=N; for(intI=0; i<=n; i++) g[i].clear (); Edges.clear (); } voidAddedge (int from,intTo,intCapDoubleCost ) {Edge E; E. from= from, e.to=to,e.cap=cap,e.flow=0, e.cost=Cost ; Edges.push_back (e); E. from=to,e.to= from, e.cap=0, e.flow=0, e.cost=-Cost ; Edges.push_back (e); M=edges.size (); g[ from].push_back (M-2); G[to].push_back (M-1); } BOOLBellmanford (intSintTint& Flow,Double&Cost ) { for(intI=0; i<=n; i++) d[i]=INF; memset (INQ,0,sizeof(INQ)); D[s]=0; Inq[s]=1; P[s]=0; A[s]=INF; Queue<int>Q; Q.push (s); while(!Q.empty ()) { intu=Q.front (); Q.pop (); Inq[u]=0; for(intI=0; i< (int) G[u].size (); i++) {Edge& e=Edges[g[u][i]]; if(e.cap>e.flow&&d[e.to]-d[u]-e.cost>ESP) {D[e.to]=d[u]+E.cost; P[e.to]=G[u][i]; A[e.to]=min (a[u],e.cap-E.flow); if(!Inq[e.to]) {Q.push (e.to); Inq[e.to]=1; } } } } if(D[t]==inf)return false; Flow+=A[t]; Cost+=d[t]*A[t]; intu=T; while(u!=s) {Edges[p[u]].flow+=A[t]; Edges[p[u]^1].flow-=A[t]; U=edges[p[u]]. from; } return true; } DoubleMincost (intSintt) {intflow=0; Doublecost=0; while(Bellmanford (s,t,flow,cost)); returnCost ; }} MCMF;intMain () {intT,n,m,s,b,u,v,c; DoublePi; scanf ("%d",&t); while(t--) {scanf ("%d%d",&n,&m); Mcmf.init (n+2); for(intI=1; I<=n; i++) {scanf ("%d%d",&s,&b); if(s>b) {MCMF. Addedge (0, I,s-b,0); } Else if(b>s) {MCMF. Addedge (I,n+1, B-s,0); } } for(intI=1; I<=m; i++) {scanf ("%D%D%D%LF",&u,&v,&c,&pi); if(c>0) MCMF. Addedge (U,v,1,0); if(C-1>0) {MCMF. Addedge (U,v,c-1,-log (1.0-pi)); }} printf ("%.2lf\n",1.0-exp (-MCMF. Mincost (0, n+1))); } return 0;}
hdu5988 minimum cost maximum flow floating point