http://poj.org/problem?id=3122
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const double K=1e-4;
const double PI=acos(-1);
const int N=10005;
double size[N];
int n,F;
bool toosmall(double k)
{
int sum=0;
for(int i=0;i<=n;++i)
{
sum+=(int)(size[i]/k);
}
if(sum>=(F+1))
return true;
return false;
}
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>n>>F;
double Max=0;
double sum=0;
for(int i=1;i<=n;++i)
{
int k;
cin>>k;
size[i]=k*k*PI;
sum+=size[i];
if(size[i]>Max)
Max=size[i];
//cout<<size[i]<<" ";
}
double high=(sum)/(F+1);
double low=(Max)/(F+1);
double mid=(high+low)/2;
while(high-low>K)
{
if(toosmall(mid))
{
low=mid;
}
else
{
high=mid;
}
mid=(high+low)/2;
}
printf("%.3f\n",mid);
}
return 0;
}