美文网首页
680. 剪绳子 (二分)

680. 剪绳子 (二分)

作者: 来到了没有知识的荒原 | 来源:发表于2021-01-15 23:22 被阅读0次
    1. 剪绳子 (二分)

    https://www.acwing.com/activity/content/problem/content/3418/1/

    胡写

    #include<bits/stdc++.h>
    
    using namespace std;
    const int N = 100010;
    double a[N];
    int n, m;
    
    bool check(double len){
        int cnt=0;
        for(int i=0;i<n;i++){
            int c=a[i]/len;
            cnt+=c;
        }
        return cnt<m;
    }
    
    int main() {
        cin >> n >> m;
        for (int i = 0; i < n; i++)cin >> a[i];
        double l = 0, r = 1e9;
    
        while (fabs(r - l) > 0.001) {
            double m = (l + r) / 2;
            if(check(m))r=m;
            else l=m;
        }
    
        printf("%.2f", l);
    
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:680. 剪绳子 (二分)

          本文链接:https://www.haomeiwen.com/subject/dfugaktx.html