POJ 3122-Pie(二分+精度),poj3122-pie

來源:互聯網
上載者:User

POJ 3122-Pie(二分+精度),poj3122-pie

題目地址:POJ 3122

題意:給出n個pie的直徑,有F+1個人,如果給每人分的大小相同(形狀可以不同),每個人可以分多少。要求是分出來的每一份必須出自同一個pi(既當pie大小為3,2,1,只能分出兩個大小為2的份,剩下兩個要扔掉。)

思路:對每一個人分的大小進行二分。注意講pi放在最後成,可以提高精度。

Ps:wa了5發,不知道錯在哪,然後把輸出的%lf改成%f就A了,並不知道為什麼。。。sad

#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const double pi= acos(-1.0);const double esp=1e-6;const int maxn=10010;double a[maxn];int main(){    int T,n,F;    scanf("%d",&T);    while(T--){        double low=0,high=0;        scanf("%d %d",&n,&F);        F+=1;        for(int i=0;i<n;i++){            scanf("%lf",&a[i]);            a[i]=a[i]*a[i];            high=max(high,a[i]);        }        double mid;        int cnt;        while(high-low>esp){            cnt=0;            mid=(low+high)/2;            for(int i=0;i<n;i++)                cnt+=(int)(a[i]/mid);            if(cnt>=F){                low=mid;            }            else                high=mid;        }        printf("%.4f\n",mid*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.