Pie noi

Description
My birthday is coming! According to the custom, I need to distribute some to everyone. I have N pies with different tastes and sizes. There are F friends who will come to my party, and everyone will get a piece of pie (it must be a piece of a pie, not a small piece of several pie; it can be a whole pie).

My friends are very stingy, if someone gets a bigger piece, they will start to complain. So everyone gets the same size (but it does n’t need to be the same shape). Although some of these facts will be wasted, it ’s better than messing up the whole party. Of course, I have to keep a piece for myself, and this piece should be the same size as other people.

What is the largest pie we each get? Each pie is a cylinder with a height of 1 and unequal radius.

Input The
first line contains two positive integers N and F, 1 ≤ N, F ≤ 10 000, which represents the number of pie and the number of friends.
The second line contains N integers between 1 and 10000, representing the radius of each pie.
Output
Outputs the largest pie volume that everyone can get, accurate to three decimal places.
Sample input
3 3
4 3 3
Sample output
25.133

note

1. The accuracy of
pi should be as large as possible 2. The right should be as large as possible, it is best to get 3.
f to add one, and also count yourself

#include <iostream>
using namespace std;
double l=0,r=0;
double sz[10010];
static double PI=3.141592653589793238;
int main(){
    int N,F;
    scanf("%d %d",&N,&F);
    F++;
    for (int i = 0; i < N; ++i) {
        int temp;
        scanf("%d",&temp);
        sz[i]=PI*temp*temp;
        if(sz[i]>r)r=sz[i];
//        printf("%.5lf\n",sz[i]);
    }
    while (r-l>1e-6){
        double mid=(r+l)/2;
        int num=0;
        for (int i = 0; i < N; ++i) {
            num+=sz[i]/mid;
        }
        if(num>=F){
            l=mid;
        } else{
            r=mid;
        }
    }
    printf("%.3lf",l);
}
Published 163 original articles · praised 18 · visits 7683

Guess you like

Origin blog.csdn.net/xcdq_aaa/article/details/105456704