和方格取数类似的建图,基本上读完题就能看出来了,简单的最小割,至于取对数是常用方法,没什么好说的
网络流一般都是int的,double只要加一个eps精度判定就可以了~~
一次性编译 + 一次性ac~~看来我变强了。。。︿( ̄︶ ̄)︽( ̄︶ ̄)︿飞.飞.飞.
#include<iostream> #include<vector> #include<algorithm> #include<cstdio> #include<queue> #include<stack> #include<string> #include<map> #include<set> #include<cmath> #include<cassert> #include<cstring> #include<iomanip> using namespace std; #ifdef _WIN32 #define i64 __int64 #define format "%I64d\n" #else #define i64 long long #define format "%lld\n" #endif #define CC(m,what) memset(m,what,sizeof(m)) #define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++) #define FF(i,a) for( int i = 0 ; i < (a) ; i ++) #define FFD(i,a) for( int i = (a)-1 ; i >= 0 ; i --) #define SS(a) scanf("%d",&a) #define LL(a) ((a)<<1) #define RR(a) (((a)<<1)+1) #define PP(n,m,a) puts("---");FF(i,n){FF(j,m)cout << a[i][j] << ' ';puts("");} #define pb push_back #define CL(Q) while(!Q.empty())Q.pop() #define MM(name,what) memset(name,what,sizeof(name)) #define read freopen("in.txt","r",stdin) #define write freopen("out.txt","w",stdout) const int inf = 0x3f3f3f3f; const double oo = 10e9; const double eps = 1e-10; const double PI = acos(-1.0); const int maxn=111; const int end=110; struct zz { int from; int to; int id; double c; }zx,tz; int T,m,n,l,tx,ty; double td; double sx[maxn]; double sy[maxn]; vector<zz>g[maxn]; queue<int>q; int cen[maxn]; inline void init() { FF(i,maxn) g[i].clear(); return ; } bool bfs() { CL(q); MM(cen,-1); cen[0] = 0; q.push(0); int now,to; while(!q.empty()) { now = q.front(); q.pop(); FF(i,g[now].size()) { to = g[now][i].to; if( g[now][i].c > eps && cen[to] == -1) { cen[to] = cen[now] + 1; q.push(to); } } } return cen[end] != -1; } double dfs(double flow = oo , int now = 0 ) { if(now == end) { return flow; } double temp,sum=0.0; int to; FF(i,g[now].size()) { to = g[now][i].to; if( cen[to] == cen[now] + 1 && flow - sum > eps && g[now][i].c > eps ) { temp = dfs ( min ( flow - sum , g[now][i].c ) , to ); sum += temp; g[now][i].c -= temp; g[to][g[now][i].id].c += temp; } } if(sum < eps) cen[now] = -1; return sum; } double dinic() { double ans=0.0; while( bfs() ) { ans += dfs(); } ans = exp (ans); return ans; } int main() { cin>>T; while(T--) { cin>>m>>n>>l; init(); for(int i=1;i<=m;i++) { cin>>td; td = log(td); sx[i] = td; } for(int i=1;i<=n;i++) { cin>>td; td = log(td); sy[i] = td; } FOR(i,1,m) { zx.from = 0; zx.to = i; zx.c = sx[i]; zx.id = g[i].size(); g[0].pb(zx); swap (zx.from , zx.to); zx.c = 0; zx.id = g[0].size() - 1; g[i].pb(zx); } FOR(i,1,n) { zx.from = 50 + i; zx.to = end; zx.c = sy[i]; zx.id = g[end].size(); g[50+i].pb(zx); swap (zx.from , zx.to); zx.c = 0; zx.id = g[50+i].size() - 1; g[end].pb(zx); } FOR(i,1,l) { cin>>tx>>ty; zx.from = tx; zx.to = ty + 50; zx.c = oo; zx.id = g[zx.to].size(); g[tx].pb(zx); swap (zx.from , zx.to); zx.c=0; zx.id = g[tx].size() - 1; g[zx.from].pb(zx); } cout.setf(ios::fixed); cout<< setprecision(4) << dinic() <<endl; } return 0; }