Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 13258 | Accepted: 4564 | Special Judge |
Description
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