原来是二分
谁对平均分贡献大选谁
界限<0.001,100次足矣
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=1010;
int n,k;
double mid;
struct Node{
double a,b;
}w[maxn];
bool cmp(Node x,Node y){
return x.a-x.b*mid>y.a-y.b*mid;
}
bool cheak(){
sort(w,w+n,cmp);
double s=0;
for(int i=0;i<n-k;++i)
s+=w[i].a-w[i].b*mid;
return s>=0;
}
int main(){
double l,r;
int ans;
while(scanf("%d%d",&n,&k)&&n+k){
for(int i=0;i<n;++i)scanf("%lf",&w[i].a);
for(int i=0;i<n;++i)scanf("%lf",&w[i].b);
l=0;r=1;
for(int i=0;i<100;++i){
mid=(l+r)/2;
if(cheak())l=mid;
else r=mid;
}
ans=l*100+0.5;
cout<<ans<<endl;
}
return 0;
}
标签:Node,int,double,mid,POJ,bool,include,2976
From: https://www.cnblogs.com/zan-mei-tai-yang/p/18395171