| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
why WA?????有谁帮我看一下????#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator