Pie
Click to open the topic link
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 10595 |
|
Accepted: 3733 |
|
Special Judge |
Description 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 (and not necessarily equally shaped) pieces, even if this 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 different.
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≤10 000:the number of pies and the number of F Riends. One line with N integers ri with 1≤ri≤10 000:the radii of the Pies.
Output for each test case, output one line with the largest possible volume V such then me and my friends can all get a pi e Piece of Size v. The answer should is given as a floating point number with an absolute error of in most 10−3.
Sample Input
3
3 3
4 3 3 1 5 5 1 4
2 3 4 5 6 5 4 2
Sample Output
25.1327
3.1416
50.2655
Source Northwestern Europe 2006
Title: A total of n cakes, now there are f+1 individuals to participate in the party, now the pie into the f+1 block of the same size of the cake (can only be a piece, not many pieces). What is the maximum volume of the pie that is asked to be divided? (The height is 1, the radius problem is given, the cake is the regular cylinder);
Two points, here looks like a greedy thought, the first average points, and then see if there is not enough points, if not enough points, and then take the middle number, and finally reached the accuracy, the accuracy of the card is more severe, POJ handed over to use%.4F,HDU on the problem.
Code:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define N 10010
#define PI ACOs ( -1)
using namespace std;
int a[n];
Double v[n];
int main ()
{
int t,n,f,i;
while (~SCANF ("%d", &t))
{while
(t--)
{
scanf ("%d%d", &n,&f);
f++;
Double sum=0;
for (i=0; i<n; i++)
{
scanf ("%d", &a[i]);
V[i]=a[i]*a[i];
Sum+=v[i];
}
Double mid=0,low=0,height=sum/f;
while (height-low>1e-6)
{
mid= (height+low)/2;
int cnt=0;
for (i=0; i<n; i++)
cnt+=int (v[i]/mid);
if (cnt>=f)
low=mid;
else
height=mid;
}
printf ("%.4f\n", Mid*pi);
}
}
return 0;
}