zoukankan      html  css  js  c++  java
  • poj 1064 Cable master

    题意:给n段绳子,长度分别为c1,c2.....,切成相等的k段,求最大的长度

    分析:二分长度,唯一注意的一点,输出的时候的精度

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    const int maxn=1e4+5;
    const double esp=1e-9;
    double c[maxn];
    int n,k;
    
    bool judge(double mid){
        int cnt=0;
        for(int i=0;i<n;i++)
          cnt+=(int)(c[i]/mid);
        return cnt>=k;
    }
    
    int main(){
        while(~scanf("%d%d",&n,&k)){
            double l=0,r=0;
            for(int i=0;i<n;i++){
                scanf("%lf",c+i);
                r+=c[i];
            }
            r/=k;
            while(r-l>esp){
                double mid=(l+r)/2;
                if(judge(mid))
                  l=mid;
                else
                  r=mid;
            }
            r=floor(r*100)/100;
            printf("%.2f
    ",r);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    植物园偶遇一直喵
    植物园偶遇一直喵
    美食篇
    美食篇
    端午节路过南站
    端午节路过南站
    黄山云海
    黄山云海
    Android (1)
    树和树算法(1)
  • 原文地址:https://www.cnblogs.com/jihe/p/5571278.html
Copyright © 2011-2022 走看看