二分。
1 #include <stdio.h> 2 #include <math.h> 3 4 const double eps = 1e-6; 5 double areas[10001]; 6 7 int main() { 8 int case_n, n, f, m; 9 double r, sum, l, mid, PI; 10 int i; 11 12 PI = acos(-1); 13 14 scanf("%d", &case_n); 15 16 while (case_n--) { 17 scanf("%d %d", &n, &f); 18 sum = 0.0f; 19 for (i=0; i<n; ++i) { 20 scanf("%lf", &r); 21 areas[i] = PI*r*r; 22 sum += areas[i]; 23 } 24 l = 0.0f; 25 ++f; 26 r = sum/f; 27 while (r-l > eps) { 28 mid = (l+r)/2; 29 m = 0; 30 for (i=0; i<n; ++i) 31 m += (int)(areas[i]/mid); 32 if (m < f) 33 r = mid; 34 else 35 l = mid; 36 } 37 printf("%.4lf ", l); 38 } 39 40 return 0; 41 }