POJ 3122 Pie 二分

來源:互聯網
上載者:User

題意:有N塊餡餅,要分給F+1個人。

1.可以將一塊餡餅分成若干份,但是每個人最多隻能拿一塊餡餅。

2.所有人的餡餅面積必須i相同。

求每個人最多能拿到的餡餅的面積。

#include<cstdio>#include<cmath>using namespace std;const double eps = 1e-6;const double pi = acos(-1.0);int R[20000], N, F;bool check ( double num ){    double cnt = 0;    for ( int i = 0; i < N; i++ )    {        cnt += floor(R[i]/num);        if ( cnt >= F ) return true;    }    return false;}double bfind ( double left, double right ){    double mid;    while ( left + eps < right )    {        mid = (left + right) / 2;        if ( check (mid) ) left = mid;        else right = mid;    }    return right;}int main(){    int t;    scanf("%d",&t);    while (t--)    {        scanf("%d%d",&N,&F);        F = F + 1;        double aver = 0;        for( int i = 0; i < N; i++)        {            scanf("%d",&R[i]);            R[i] = R[i] * R[i];            aver += R[i];        }        double ret = bfind ( 0, aver/F );        printf("%.4lf\n",ret*pi);    }    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.