| ||||||||||
| 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 | |||||||||
cin 超时啊!!#include <iostream>
#include <algorithm>
#include <cstdio>
#include <ctime>
#include <cstdlib>
using namespace std;
const int maxn=1005;
double a[maxn],b[maxn],d[maxn];
const double eps=1e-6;
int n,k;
bool cal(double mid)
{
for(int i=0;i<n;i++)
d[i]=a[i]-mid*b[i];
sort(d,d+n);
double sum=0;
for(int i=k;i<n;i++)
sum+=d[i];
if(sum>0)return 1;
else return 0;
}
int main()
{
while(scanf("%d%d", &n, &k) != EOF)
{
if(n+k==0)break;
for(int i=0;i<n;i++)
scanf("%lf", &a[i]);
for(int i=0;i<n;i++)
scanf("%lf", &b[i]);
double l=0.0,r=1.0;
//clock_t t1=clock();
while(r-l>=eps)
{
double mid=(l+r)/2;
if(cal(mid))l=mid;
else r=mid;
}
printf("%.0f\n", l * 100);
//clock_t t2=clock();
//cout<<t2-t1<<" ms"<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator