Description
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though.Input
One line with a positive integer: the number of test cases. Then for each test case: One line with two integers N and F with 1 ≤ N, F ≤ 10 000: the number of pies and the number of friends.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 that me and my friends can all get a pie piece of size V. The answer should be given as a floating point number with an absolute error of 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
Source
Northwestern Europe 2006#include#include #include using namespace std; int const MAX = 1e4; double const PI = 4.0 * atan(1.0); double const EPS = 1e-5; double R[MAX]; bool cmp(double a, double b) { return a > b; } int main() { int T, n; scanf("%d", &T); while(T--) { double r, l, mid, sum = 0, mi = 1e10, f; scanf("%d %lf", &n, &f); f += 1; for(int i = 0; i < n; i++) { scanf("%lf", &R[i]); sum += (PI * R[i] * R[i]); } sort(R, R + n, cmp); r = sum / f; l = R[n - 1] * R[n - 1] * PI / f; mid = (l + r) / 2; while(r - l > EPS) { int cnt = 0; for(int i = 0; i < n; i++) { if((R[i] * R[i] * PI) / mid > 1.0 - 1e-10) cnt += (R[i] * R[i] * PI) / mid; else break; } if(cnt >= f) l = mid + EPS; else r = mid - EPS; mid = (l + r) / 2; } printf("%.4f\n", mid); } }