POJ2976 Dropping tests 01分数规划

时间:2021-12-30 01:55:02

裸题

看分析请戳这里:http://blog.csdn.net/hhaile/article/details/8883652

#include<stdio.h>
#include<algorithm>
using namespace std;
const int N=1e3+;
const double eps=1e-;
int n,k;
double a[N],b[N],c[N];
int main() {
while(~scanf("%d%d",&n,&k)){
if(!n&&!k)break;
for(int i=;i<=n;++i)scanf("%lf",&a[i]);
for(int i=;i<=n;++i)scanf("%lf",&b[i]);
double l=0.0,r=1.0,mid;
while(r-l>eps){
mid=(l+r)/;
for(int i=;i<=n;++i)
c[i]=a[i]-mid*b[i];
sort(c+,c++n);
double sum=;
for(int i=k+;i<=n;++i)
sum+=c[i];
if(sum>)l=mid;
else r=mid;
}
printf("%.0f\n",mid*);
}
return ;
}