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

谁帮我看一看哪里错了啊?wa死我了

Posted by fyq at 2009-12-18 11:46:22 on Problem 2112
#include <cstdio>
#include <cstring>
#define oo 2147483647

using namespace std;

int k,c,m,maxe,n;
int g[300][300],gt[300][300];
bool mark[300];

void ini()
{
	int i,j,t;
	scanf("%d%d%d",&k,&c,&m);
	maxe = 0;
	n = k+c;
	for (i=1;i<=n;i++)
		for (j=1;j<=n;j++)
			gt[i][j] = oo;
	for (i=1;i<=n;i++)
		{
			for (j=1;j<=n;j++)
			{
				scanf("%d",&gt[i][j]);
				if (gt[i][j]>maxe) maxe = gt[i][j];
				if (gt[i][j]==0) gt[i][j] = oo;
			}
		}
	for (t=1;t<=n;t++)//floyd求最短路
		for (i=1;i<=n;i++)
			for (j=1;j<=n;j++)
				if ((gt[i][t]<oo)&&(gt[t][j]<oo))
				if (gt[i][t]+gt[t][j]<gt[i][j])
				{
					gt[i][j] = gt[i][t]+gt[k][t];
				}
	n += 2;
}

int dfs_maxflow(int x,int low)//朴素的最大流算法
{
	int i,flow;
	if (x==n) return low;
	if (mark[x]) return 0;
	mark[x] = 1;
	for (i=1;i<=n;i++)
		if (g[x][i])
		{
			if (low<g[x][i]) flow = dfs_maxflow(i,low);
				else flow = dfs_maxflow(i,g[x][i]);	
			if (flow>0)
				{
					g[x][i] -= flow;
					g[i][x] += flow;
					return flow;
				}				
		}
	return 0;
}

bool make(int p)//用最大流判断当前解可行性
{
	int i,j,ans = 0,temp = oo;
	memset(g,0,sizeof(g));
	for (i=1;i<=k;i++)
		for (j=k+1;j<=k+c;j++)
			if (gt[i][j]<=p)
				{
					g[i][j] = 1;//如果i机器到j牛最短路<=p,容量就定为一
				}
	for (i=1;i<=k;i++)//把源点到所有机器连容量为m的边
		g[n-1][i] = m;
	for (i=k+1;i<=k+c;i++)//把所有奶牛到汇点连容量为1的边
		g[i][n] = 1;
	while (temp)
		{
			memset(mark,0,sizeof(mark));
			temp = dfs_maxflow(n-1,oo);
			ans += temp;
		}
	//printf("%d %d\n",p,ans);
	if (ans==c) return 1;//最大流=牛的数目就可行
	return 0;
}

void work()
{
	int l,r,mid;
	bool temp;
	l = 0; r = maxe+1;
	while (l<r)
		{
			mid = (l+r)/2;
			temp = make(mid);
			if (temp)
				r = mid;
			else
				l = mid+1;
		}
	printf("%d\n",l);
}

int main()
{
	ini();
	work();
	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