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 Ikki at 2005-06-30 10:40:12 on Problem 2400
大家帮忙啊……
//2400.cpp
//Supervisor, Supervisee

//By phoenixinter
//On 6/30/2005

#include<stdio.h>
#include<algorithm>
using namespace std;

int sup[15][15],emp[15][15],perm[15],n;
int tempans[10000][15],p,min;
bool used[15];

void dfs(int depth,int ans)
{
	if(ans>min) return;
	int i;
	if(depth>n)
	{
		//sum++;
		if(ans==min)
		{	
			for(i=1;i<=n;i++)
				tempans[p][i]=perm[i];
			p++;
		}
		else if(ans<min)
		{
			min=ans;
			p=0;
			for(i=1;i<=n;i++)
				tempans[p][i]=perm[i];
			p++;
		}
		return;
	}
	else
	{
		for(i=1;i<=n;i++)
			if(!used[i])
			{
				used[i]=true;
				perm[depth]=i;
				dfs(depth+1,ans+sup[depth][i]+emp[i][depth]);
				used[i]=false;
			}
	}
}

int main()
{
	int no_case,i,j,k,temp;
	scanf("%d",&no_case);
	for(i=1;i<=no_case;i++)
	{
		scanf("%d",&n);
		//sum=0;
		memset(used,false,sizeof(used));
		min=2147483647;
		p=0;
		for(j=1;j<=n;j++)
			for(k=1;k<=n;k++)
			{
				scanf("%d",&temp);
				sup[j][temp]=k-1;
			}
		for(j=1;j<=n;j++)
			for(k=1;k<=n;k++)
			{
				scanf("%d",&temp);
				emp[j][temp]=k-1;
			}
		printf("Data Set %d, ",i);
		dfs(1,0);
		//printf("Generated %d permutations:\n",sum);
		printf("Best average difference: %.6lf\n",min/2.0/n);
		for(j=0;j<p;j++)
		{
			printf("Best Pairing %d\n",j+1);
			for(k=1;k<=n;k++)
				printf("Supervisor %d with Employee %d\n",k,tempans[j][k]);
		}
		if(i!=no_case) printf("\n");
	}
	return 0;
}
我估计是average difference求错了……

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