• poj2976 Dropping tests (01分数规划)


    裸题。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<vector>
     5 #include<queue>
     6 #include<cmath>
     7 #include<ctime>
     8 #define LL long long int
     9 #define inf 0x3f3f3f3f
    10 using namespace std;
    11 const int maxn=1010;
    12 
    13 LL rd(){
    14    LL x=0;char c=getchar();int neg=1;
    15    while(c<'0'||c>'9'){if(c=='-') neg=-1;c=getchar();}
    16    while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    17    return x*neg;
    18 }
    19 
    20 int N,K,A[maxn],B[maxn];double x[maxn]; 
    21 
    22 bool judge(double r){
    23     for(int i=1;i<=N;i++) x[i]=A[i]-B[i]*r;
    24     sort(x+1,x+1+N);double re=0;
    25     for(int i=N;i>K;i--){
    26         re+=x[i];
    27     }return re>=0;
    28 }
    29 
    30 int main(){
    31     int i,j,k;
    32     while(1){
    33         N=rd(),K=rd();if(!N) break;
    34         for(i=1;i<=N;i++) A[i]=rd();
    35         for(i=1;i<=N;i++) B[i]=rd();
    36         double l=0,r=1;
    37         while(fabs(l-r)>1e-6){
    38             double m=(l+r)/2;
    39             if(judge(m)) l=m+1e-6;
    40             else r=m-1e-6;
    41         }printf("%d
    ",(int)(l*100+0.5));
    42     }
    43     return 0;
    44 }
  • 相关阅读:
    CodeForces
    HihoCoder
    HihoCoder
    CodeForces
    CodeForces
    CodeForces
    HihoCoder
    HihoCoder
    CodeForces
    HihoCoder
  • 原文地址:https://www.cnblogs.com/Ressed/p/9581705.html
Copyright © 2020-2023  润新知