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

有人人告诉为什么我的代码tle吗? 找不出错误来!!!

Posted by yangzefeng1 at 2012-11-30 21:57:15 on Problem 3686
#include<iostream>
#include<algorithm>

using namespace std;

#define MAX 51*51
#define INF 999999999

int map[51][MAX];
int lx[51], ly[MAX];
int match[51];
bool visx[51], visy[MAX];
int nN, nM;

void vInput()
{
	int i, j, k, val;

	cin >> nN >> nM;
	for(i = 1; i <= nN; i++)
	{
		for(j = 1; j <= nM; j++)
		{
			cin >> val;
			for(k = 1; k <= nN; k++)
				map[i][(j-1)*nN + k] = -val * k;
		}
	}
}

bool dfs(int u)
{
	int i;

	visx[u] = true;
	for(i = 1; i <= nN*nM; i++)
	{
		if(!visy[i] && (lx[u] + ly[i] == map[u][i]))
		{
			visy[i] = true;
			if(match[i] == 0 || dfs(match[i]))
			{
				match[i] = u;
				return true;
			}
		}
	}
	return false;
}

int km()
{
	int i, j, k, d, nRet;

	//初始化
	for(i = 1; i <= nN; i++)
	{
		lx[i] = -INF;
		for(j = 1; j <= nN*nM; j++)
			if(map[i][j] > lx[i])
				lx[i] = map[i][j];
	}

	memset(match, 0, sizeof(match));
	memset(ly, 0, sizeof(ly));

	for(i = 1; i <= nN; i++)
	{
		while(!dfs(i))
		{
			memset(visx, false, sizeof(visx));
			memset(visy, false, sizeof(visy));

			d = INF;
			for(j = 1; j <= nN; j++)
			{
				if(visx[j])
				{
					for(k = 1; k <= nN*nM; k++)
						if(!visy[k] && d > (lx[j] + ly[k] - map[j][k]))
							d = lx[j] + ly[k] - map[j][k];
				}
			}

			for(j = 1; j <= nN; j++)
				if(visx[j])
					lx[j] -= d;
			for(k = 1; k <= nN*nM; k++)
				if(visy[k])
					ly[k] += d;
		}
	}

	nRet = 0;
	for(i = 1; i <= nN*nM; i++)
		nRet += map[match[i]][i];

	return -nRet;
}

void vOut(int out)
{
	double dAns;
	dAns = 1.0 * out / nN;
	printf("%.6f\n", dAns);
}

int main()
{
	int nTest;
	int nTemp;

	cin >> nTest;
	while(nTest--)
	{
		vInput();
		nTemp = km();
		vOut(nTemp);
	}
	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