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

why WA?????有谁帮我看一下????

Posted by BJ051155 at 2007-07-22 20:39:27 on Problem 2976
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *a,const void *b)
{
	return *(double *)b-*(double *)a;
}
int main(int argc, char* argv[])
{
	long n,k,a[1000],b[1000];
	while(scanf("%d%d",&n,&k)&&n+k)
	{
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(i=0;i<n;i++)
			scanf("%d",&b[i]);
		double min=0.0;
		double max=1.0,mid,r[1000];
		while(max-min>0.0000001)
		{
			mid=(max+min)/2.0;
			for(i=0;i<n;i++)
				r[i]=a[i]-mid*b[i];
			qsort(r,n,sizeof(r[0]),cmp);
			double sum=0;
			for(i=0;i<n-k;i++)
				sum+=r[i];
			if(sum>=0)
				min=mid;
			else
				max=mid;
		}
		printf("%d\n",(int)(100*min+0.5));
	}
	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