poj 1064 Cable master

poj 1064 Cable master,第1张

poj 1064 Cable master
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 10005int n, k;long long f[maxn];long long sum;bool ok(long long a){    long long cnt = 0;    for (int i = 0; i < n; i++)        cnt += f[i] / a;    return cnt >= k;}long long binarysearch(long long l, long long r){    while (l < r)    {        long long mid = (l + r) / 2 + ((l + r) & 1);        if (!ok(mid)) r = mid - 1;        else l = mid;    }    if (!ok(l))        return -1;    return l;}int main(){    scanf("%d%d", &n, &k);    for (int i = 0; i < n; i++)    {        double a;        scanf("%lf", &a);        f[i] = a * 100;        sum += f[i];    }    long long ans = binarysearch(1, sum / k);    if (ans == -1)        printf("0.00n");    else        printf("%lld.%02lldn", ans / 100, ans % 100);    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4891483.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存