My birthday is coming up and traditionally I ' m serving pie. Not just one pie, no, I had a number N of them, of various tastes and of various sizes. F of my
Friends is coming to my party and each of the them gets a piece of pie. This should is one piece of one pie, not several small pieces since that looks messy. This
Piece can be one whole pie though. My Friends is very annoying and if one of them gets a bigger piece than the others, they start complaining. Therefore all of
them should get equally sized (but not necessarily equally shaped) pieces, even if the leads to some pie getting spoiled (which is better than spoiling the
Party). Of course, I want a piece of pie for myself too, and that piece should also is of the same size. What's the largest possible piece size all of us can get?
All the Pies is cylindrical in shape and they all has the same height 1, but the radii of the Pies can is di?erent.
Input
One line with a positive integer:the number of test cases. Then for each test case: one line with the integers N and F with 1≤n, f≤10000:the number
of pies and the number of friends. one line with N integers ri with 1≤ri≤10000:the radii of the Pies.
Output
For each test case, output one line with the largest possible volume V such that me and my friends can all get a pie piece of Size v. The answer should be
Given as a oating point number with an absolute error of the at most 10−3.
Sample Input
3 3 3 4 3 3 1 24 5 10 5 1 4 2 3 4 5 6 5 4 2
Sample Output
25.1327 3.1416 50.2655
I have a birthday party invited F a friend, the party has n pieces of cake, the height of the cake is 1, respectively, give the area of the n piece of cake, to make me and f friend each of the pie size of the same volume,
Ask for the maximum volume of each person.
Note: Each person can only get a piece of cake and cannot be composed of two or two different cakes.
Analysis: First use to find out the volume of each pie, and then add them together to find the total volume (v), with v divided by total number (f+1) per person can get the largest pie, because each person cannot be two and two pieces of different cake combination,
So it is necessary to v/(F+1) two points until the largest and most suitable value is found.
The code is as follows:
#include<iostream>#include<cstdio>#include<cmath>Double pi=ACOs(-1);Constint MAXN=10005;Double A[MAXN];int nF;UsingNamespace Std;boolTest(Double X){int num=0;For(int I=0; I<n; I++){num+=Int(A[I]/x);}If(num>=f)ReturnTrue;ElseReturnFalse;}IntMain(){int TR;Double MaxV, left, right, mid;scanf("%d", &t);While(t--){scanf("%d%d", &n, &f); F=f+1;For(int I=0; I<n; I++){scanf("%d", &r); A[I]=pi*r*r; V+=a[I];} max=v/F; Left=0.0; Right=max;While(Right-left) >1e-6) {mid= ( Right+left)/2if (test (mid =mid; else right=mid; printf (\n ",mid ); }} /span>
Program c--two minutes