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 sail6 at 2006-08-22 08:54:24 on Problem 2976
#include<iostream.h>


int main()
{
	double  a[1010],b[1010];
	int n,k;
	
	while(cin>>n>>k)
	{
		if(n==0&&k==0)break;
		
		int i,j;
		double c[1010]={0};
		int cur=0;
		
		for(i=0;i<n;i++)
		{
			cin>>a[i];			
		}
		for(i=0;i<n;i++)
		{
			cin>>b[i];
		}
		double max=0;
		double temp=0;
		for(i=0;i<n;i++)
		{
			temp=a[i]/b[i];
			if(temp>max)
			{
				cur=i;
				max=temp;
			}
		}
		//cout<<endl;
		double aa=a[cur],bb=b[cur];
		c[cur]=1;
		int count=1;
		for(i=0;i<n;i++)
		{
			if(count==n-k)break;
			if(c[i]==0)
			{
				double s=(aa+a[i])/(bb+b[i]);
				cur=i;
				for(j=0;j<n;j++)
				{
					if(c[j]==0&&i!=j)
					{
						double run=(aa+a[j])/(bb+b[j]);
						if(run>s)
						{
							s=run;							
							cur=j;
						}
					}
				}
				c[cur]=1;
				count++;
				aa+=a[cur];
				bb+=b[cur];
			}
		}
		cout<<(int)(100*aa/bb)<<endl;
	}
	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