解释都在大白书上,我就不再造车轮了,上代码:
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
const int maxn=1e4+5;
const double pi=acos(-1);
double a[maxn];
int n,f;
bool ok(double s)
{
int sum=0;
for(int i=0;i<n;i++)sum+=floor(a[i]/s);
return sum>=f+1;
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&f);
double r;
double m=-1;
for(int i=0;i<n;i++){
scanf("%lf",&r);
a[i]=pi*r*r;
m=max(m,a[i]);
}
double R=0,L=m;
while(L-R>1e-5){
double mid=(L+R)/2;
if(ok(mid))R=mid;
else L=mid;
}
printf("%.4f\n",L);
}
return 0;
}