POJ 1064 Cable master(初遇二分),poj1064

來源:互聯網
上載者:User

POJ 1064 Cable master(初遇二分),poj1064

題目連結:http://poj.org/problem?id=1064

題意:有n條繩子,他們的長度是Li,如果從他們中切割出K條長度相同的繩子,這相同的繩子每條有多長,輸出至小數點後兩位

“ then the output file must contain the single number "0.00" (without quotes).”不是四捨五入到兩位,一般四捨五入題目會說“bounded to”的提示

顯然想得到的繩子越短就越能得到,繩子太長就得不到,二分搜即可

//236K94MS#include<cstdio>#include<algorithm>#include<iostream>#include<cmath>using namespace std;int n,k;double a[10100];bool judge(double x){    int cnt=0;    for(int i=1;i<=n;i++){        cnt+=a[i]/x;    }    return cnt>=k? 1:0;}int main(){    scanf("%d%d",&n,&k);    for(int i=1;i<=n;i++) scanf("%lf",&a[i]);    double lb=0,ub=100100;    while(ub-lb>1e-5){        double mid=(lb+ub)/2;        if(judge(mid)){            lb=mid;        }        else{            ub=mid;        }    }    printf("%.2f\n",floor(ub*100)/100);    return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.