| ||||||||||
| 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代码#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
typedef __int64 LL;
const int MAXN=1005;
int a[MAXN],b[MAXN];
const double eps=1e-4;
int n,k;
bool check(double val) {
double ans=0;
vector<double> tmp;
for(int i=0;i<n;i++) {
ans+=(1.0*100*a[i]-1.0*val*b[i]);
tmp.push_back(1.0*100*a[i]-1.0*val*b[i]);
}
sort(tmp.begin(),tmp.end());
for(int i=0;i<k;i++) ans-=tmp[i];
return ans>-eps;
}
int main() {
while(~scanf("%d%d",&n,&k)&&(n||k)) {
double l=0,r=100,ans=-1;
for(int i=0;i<n;i++) scanf("%d",&a[i]);
for(int i=0;i<n;i++) scanf("%d",&b[i]);
while(r-l>eps) {
double mid=(l+r)/2;
if(check(mid)) l=ans=mid;
else r=mid;
}
printf("%.0f\n",ans);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator