Pie
| Time Limit: 1000MS |
|
Memory Limit: 65536K |
| Total Submissions: 11240 |
|
Accepted: 3919 |
|
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 to each test case:
- One line with a 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 this me and my friends can all get a pie p Iece of Size v. The answer should is given as a floating point number with an absolute error of in most 10?3.
Sample Input
33 34 3 31 24510 51 4 2 3 4 5 6 5 4 2
Sample Output
25.13273.141650.2655
Source
Northwestern Europe 2006
Title Link: http://poj.org/problem?id=3122
The main idea: a person has f a friend, n faction, each pie is cylindrical, high is 1, radius for RI, ask how evenly can make everyone get as far as possible, here can not splicing, such as a pie volume of 6 I want to take 5 of them, the remaining 1 is useless, can not fill the other 4 up into 5, There is not only to give friends, they also want
Title Analysis: Gaoheng is set to 1, so the sub-volume is the sub-area, we can get the answer by the area of the two points per person, here the initial range of the upper limit for all areas and except (F+1) note here is not F, because they have to be divided, the lower limit is the smallest radius of the area except (f+1), Two points of time to set a precision, because the answer is 4 digits after the decimal point, we take 1e-5, and then two points before the best radius from the big to the small sort, so you can save a lot of time, two minutes from the big to the small take, calculate the current mid value can be divided to how many people, Note If at this time the current radius of the pie is not enough to break, the back will not have to look, because we have to sort from large to small, if the number of people greater than equals (f+1) explain the area is small, you can expand the mid, otherwise the area is large, only to reduce the mid.
#include <cstdio> #include <cmath> #include <algorithm>using namespace std;int const MAX = 1e4;double CONST PI = 4.0 * ATAN (1.0);d ouble 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); }}
POJ 3122 Pie (two points + precision)