poj 2976 Dropping tests

http://poj.org/problem?id=2976

这道题就是从n个a[i]和b[i]中去掉k个a[i]和[i]使得.最大。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 20000
 5 using namespace std;
 6 const double eps=1e-8;
 7 
 8 double a[maxn],b[maxn],c[maxn];
 9 int n,k;
10 
11 int main()
12 {
13     while(scanf("%d%d",&n,&k)!=EOF)
14     {
15         if(n==0&&k==0) break;
16         for(int i=0; i<n; i++)
17         {
18             scanf("%lf",&a[i]);
19         }
20         for(int i=0; i<n; i++)
21         {
22             scanf("%lf",&b[i]);
23         }
24         double l=0.0;
25         double r=1.0;
26         double mid;
27         while(r-l>eps)
28         {
29             double sum=0;
30             mid=(l+r)/2;
31             for(int i=0; i<n; i++)
32             {
33                 c[i]=a[i]-mid*b[i];
34             }
35             sort(c,c+n);
36             for(int j=k; j<n; j++)
37             {
38                 sum+=c[j];
39             }
40             if(sum>0)
41               l=mid;
42             else
43               r=mid;
44         }
45         printf("%.0f\n",mid*100);
46     }
47     return 0;
48 }
View Code

 

posted @ 2014-06-01 22:13  null1019  阅读(147)  评论(0编辑  收藏  举报