| ||||||||||
| 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 | |||||||||
提供ac代码这题真的卡精度,耗了一个下午,感谢lyd,顺便提供ac代码,以便后人
#include <iostream>
#include <cstdio>
#include <algorithm>
#define il inline
#define ri register
#define db double
#define exact 0.00000001
int n,k;db a[2001],b[2001],c[2001];
using namespace std;
il bool check(db);
il db dfs(db,db);
int main(){
int i,j;
while(scanf("%d%d",&n,&k),n||k){
for(i=1;i<=n;++i)scanf("%lf",&a[i]);
for(i=1;i<=n;++i)scanf("%lf",&b[i]);
printf("%0.f\n",dfs(0,1));
}
return 0;
}
il bool check(db s){
int i;db j(0);
for(i=1;i<=n;++i)c[i]=a[i]-s*b[i];
sort(c+1,c+n+1);for(i=k+1;i<=n;++i)j+=c[i];
if(j>exact)return true;return false;
}
il db dfs(db l,db r){
db mid;
while(r-l>exact){
mid=(l+r)/2;
if(check(mid))l=mid+exact;
else r=mid-exact;
}return (l+r)*50;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator