poj 3122 Pie题解

题目:

https://vjudge.net/problem/POJ-3122


二分答案直接搞就行
枚举答案,然后对每个蛋糕看能分给多少人,累加起来看与客人数比较再进行调整
poj gg了

#include
#include
#include
#define MAXN 10000+10
#define eps 1e-5
using namespace std;
const double PI=acos(-1.0);
int T,N,F;
int rr[MAXN];
double s[MAXN];
int l,r;
double left,right;
double MIN(double x,double y){return xdouble MAX(double x,double y){return x>y?x:y;}
int find(double mid){
    int cnt=0;
    for(register int i=1;i<=N;i++){
        double temp=(double)rr[i]*1.0*rr[i]*1.0*PI;
        while(temp>mid){
            cnt++;
            temp-=mid;
        }
    }
    return cnt;
}
int main(){
    scanf("%d",&T);
    while(T--){
        l=1000000.0;r=-1.0;
        scanf("%d%d",&N,&F);
        for(register int i=1;i<=N;i++){
            scanf("%d",&rr[i]);
            r=MAX(rr[i],r);
            l=MIN(rr[i],l);
        }
        double left=0.0,right=2.0*r*r*PI;
        while(left+epsdouble mid=(left+right)/2.0;
            if(find(mid)>=F+1){
                left=mid+eps;
            }else{
                right=mid+-eps;
            }
        }
        printf("%0.4lf",left);
    }
    return 0; 
} 

你可能感兴趣的:(二分)