POJ 1064 Cable Master

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;
#define maxn 10000
#define eps 1e-8
const int INF = 100000;

int n, k;
double L[maxn];

bool judge(double x)
{
    int cnt = 0;
    for(int i=0; i<n; i++)
    {
        cnt += (int)(L[i]/x);
    }
    return cnt >= k;
}

void solve()
{
    double L = 0, R = INF;
    while((R - L) > eps)
    {
        double mid = (L + R)/2;
        if(judge(mid)) L = mid;
        else R = mid;
    }
    printf("%.2lf\n", floor(R*100)/100);
}

int main()
{
    while(~scanf("%d%d", &n, &k))
    {
        for(int i=0; i<n; i++)
            scanf("%lf", &L[i]);
        solve();
    }
    return 0;
}

你可能感兴趣的:(ACM,poj)