| Time Limit: 1000MS | Memory Limit: 65536K | |||
| Total Submissions: 13258 | Accepted: 4564 | Special Judge | ||
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
Output
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
#include <cstdio> #include <cstring> #include <cmath> using namespace std; const int MAXN = 10005; const double pi = acos(-1.0); int n, f, r[MAXN]; bool check(double maxv) { long long howc = 0; for (int i = 0; i < n; ++i) howc += (long long) floor((double) r[i] * r[i] * pi / maxv); return howc >= f + 1; } void binarysearch(double L, double R) { if (R - L < 1e-5) { printf("%.4lf\n", L); return; } double mid = (L + R) / 2.0; if (check(mid)) binarysearch(mid, R); else binarysearch(L, mid); } int main() { int Test; scanf("%d", &Test); while (Test--) { scanf("%d%d", &n, &f); double maxr = 0; for (int i = 0; i < n; ++i) scanf("%d", &r[i]), maxr += r[i] * r[i]; binarysearch(0, maxr * pi); } return 0; }
原文:http://www.cnblogs.com/albert7xie/p/4905502.html