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

哪里错了啊 请大牛指点

Posted by tangbohu222 at 2011-03-26 15:52:09 on Problem 2054
#include<stdio.h>
//#include<memory.h>
int N,R;
 long int C[1001],father[1001],t[1001];
int fa,so;
long int ans=0;
void greedy()
{
	
	for(int i=1;i<=N;i++)
	{
		long  int temp,mod;
		 long double max;
		mod=0;
		max=0.0;
		temp=0;
		for(int j=1;j<=N;j++)
		{
			
			if(C[j]*1.0/t[j]>max&&j!=R)
			{
				max=C[j]/t[j];
			
				temp=j;
			}
	
		}
		for(int j=1;j<=N;j++)//
		{
			if(father[j]==temp)
				father[j]=father[temp];
		}
		ans+=t[father[temp]]*C[temp];
		C[father[temp]]+=C[temp];
		
		t[father[temp]]+=t[temp];
		C[temp]=0;

	}
	printf("%ld\n",ans);
}
int main()
{
	//freopen("a.in", "r", stdin);
   // freopen("slyar.out", "w", stdout);
	while(scanf("%d%d",&N,&R))
	{
		if(N==0&&R==0)break;
		ans=0;
	for(int i=1;i<=N;i++)
	{
		scanf("%ld",&C[i]);
		ans+=C[i];
		t[i]=1;
	}
	for(int i=1;i<=N-1;i++)
	{
		scanf("%d%d",&fa,&so);
		father[so]=fa;
	}
	
	greedy();
	}
	   // fclose(stdin);
    //fclose(stdout);
	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