Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴代码, 求debug

Posted by stupidjohn at 2011-06-07 21:28:55 on Problem 3308
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
#define MIN(a, b) ((a)<(b)?(a):(b))
#define eps 0.000000001
#define INF 1000000.0
#define maxN 210
int n, m, k, s, t;
double g[maxN][maxN];
int dist[maxN], gap[maxN], pre[maxN], cur[maxN];
double SAP(){
	int u, v;
	double maxflow=0.0, aug=INF;
	memset(dist, 0, sizeof(dist));
	memset(gap, 0, sizeof(gap));
	for(v=0; v<=n; v++) cur[v]=1;
	u=pre[s]=s; gap[0]=n;
	while(dist[s]<n){
	loop:
		for(v=cur[u]; v<=n; v++) if(g[u][v]>eps && dist[u]==dist[v]+1){
			aug=MIN(aug, g[u][v]);
			pre[v]=u; cur[u]=v; u=v;
			if(v==t){
				maxflow+=aug;
				for(u=pre[u]; v!=s; v=u, u=pre[u]){
					g[u][v]-=aug;
					g[v][u]+=aug;
				}
				aug=INF;
			}
			goto loop;
		}
		int mind=n-1;
		for(v=1; v<=n; v++) if(g[u][v]>eps && mind>dist[v]){
			cur[u]=v;
			mind=dist[v];
		}
		if((--gap[dist[u]])<=0) break;
		gap[dist[u]=mind+1]++;
		u=pre[u];
	}
	return maxflow;
}
int main(){
	int tc, a, b;
	double c;
	scanf("%d", &tc);
	while(tc--){
		scanf("%d %d %d", &n, &m, &k);
		s=n+m+1; t=n+m+2;
		memset(g, 0, sizeof(sizeof(g)));
		for(int i=1; i<=n; i++) {
			scanf("%lf", &c); g[s][i]=log(c);
		}
		for(int i=1; i<=m; i++) {
			scanf("%lf", &c); g[n+i][t]=log(c);
		}
		for(int i=0; i<k; i++){
			scanf("%d %d", &a, &b);
			g[a][b+n]=INF;
		}
		n=n+m+2;
		printf("%f\n", exp(SAP()));
	}
	return 0;
}






Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator