确定可能的切出来的饼的面积的上限和下限,然后对答案进行二分查找。
#include <stdio.h>
#include <math.h>
#define PIE (acos(-1.0))
double pie[10001];
double max;
void func(int pie_n, int people_n){
double l, r, m;
int i;
int sum;
l = 0.0; r = max;
while(1){
if(fabs(r-l) <= 1e-7)
break;
m = (l+r)/2.0;
sum = 0;
for(i=1; i<=pie_n; i++){
sum += floor(pie[i]/m);
}
if(sum >= people_n)
l = m;
else
r = m;
}
printf("%.4lf\n", m*PIE);
}
int main(void){
int n, pie_n, friend_n;
int i;
//freopen("input.dat", "r", stdin);
scanf("%d", &n);
while(n--){
scanf("%d %d", &pie_n, &friend_n);
max = -1;
for(i=1; i<=pie_n; i++){
scanf("%lf", pie+i);
pie[i] = pie[i] * pie[i];
if(max < pie[i])
max = pie[i];
}
func(pie_n, friend_n+1);
}
return 0;
}