Pie
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 11178 |
|
Accepted: 3899 |
|
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 that me and my friends can all get a pie 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
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
The main idea: give n pies, m+1 personal average of these pies, each piece, ask each person the most points.
Two cents can get the pie size. Double two points
while ((high-low) > EQs)
{
Mid = (Low+high)/2.0;
if (Solve (mid))
{
Low = mid;
last = mid;
}
Else
High = mid;
}
Note: 1 double subtraction (high-low) > EQs, EQS used for card precision, eqs too much precision reduced, eqs too small time to become high.
22 points does not add 0.0001, that is, low = mid High = Mid; This may be slower, but the accuracy will be high.
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath>using namespace std; Define PI 3.1415926535898#define eqs 1e-5double s[11000]; int n, M;d ouble F (double x) {int k = (x+eqs) * 10000; x = k * 1.0/10000; return x;} int solve (double x) {int i, j, num = 0; for (i = n-1; I >= 0 && (s[i]-x) > eqs; i--) {j = s[i]/x; num + = j; if (num >= m+1) return 1; } if (num >= m+1) return 1; return 0;} int main () {int T, I, K; Double low, mid, high, last; while (scanf ("%d", &t)! = EOF) {while (t--) {scanf ("%d%d", &n, &m); for (i = 0; i < n; i++) scanf ("%lf", &s[i]); Sort (s,s+n); for (i = 0; i < n; i++) s[i] = S[i]*s[i]*pi; Low = 0; High = s[n-1]; while ((high-low) > EQs) {mid = (Low+high)/2.0; if (Solve (mid)) {low = Mid; last = mid; } else High = mid; } printf ("%.4lf\n", last); }} return 0;}
Poj3122--pie (two-point accuracy problem)