二分答案+验证(这题精度卡的比较死)
#include<stdio.h> #include<math.h> #define eps 1e-7 const int ff = 11111; double a[ff]; double pi = acos(-1.0); int main() { int sb; scanf("%d", &sb); while (sb--) { int m, n; scanf("%d%d", &m, &n); int i, j; double maxn = 0; for (i = 1; i <= m; i++) { scanf("%lf", &a[i]); a[i] = a[i] * a[i] * pi; if (a[i] > maxn) maxn = a[i]; } double minn = 0; double midn = (minn + maxn) / 2.0; while (1) { if (maxn - minn < eps) { printf("%.4lf ", midn); break; } else { int sum = 0, flag; for (i = 1; i <= m; i++) sum += (int)((1.0*a[i] / midn)); if (sum >= n+1) flag = 1; else flag = 0; if (flag) minn = midn, midn = (minn + maxn) / 2.0; else maxn = midn, midn = (minn + maxn) / 2.0; } } } return 0; }