zoukankan      html  css  js  c++  java
  • poj1064

    二分

    简单题

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    using namespace std;

    #define maxn 10005

    int 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()
    {
    //freopen("t.txt", "r", stdin);
    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.00\n");
    else
    printf(
    "%lld.%02lld\n", ans / 100, ans % 100);
    return 0;
    }
  • 相关阅读:
    绑定姿势
    Mesh.CombineMeshes
    Mono vs IL2CPP
    lua keynote2
    lua keynote
    游戏编程模式KeyNote
    架构、性能和游戏
    Canvas
    AssetBundle Manager
    Loading AssetBundle Manifests
  • 原文地址:https://www.cnblogs.com/rainydays/p/2158104.html
Copyright © 2011-2022 走看看