#include <iostream>
#include <cmath>
using namespace std;
const double PI=acos(-1.0); //3.14过不了
double area[10005];
double max_area;
int n,f;
int OK(double k)
{ int i,Count=0;
for(i=0;i<n;i++)
Count+=floor(area[i]/k);
return Count>=f+1;
}
double binary()
{
double left=0,right=max_area,middle;
while(left<right&&(right-left)>=10e-6)
{
middle=(left+right)/2;
if(!OK(middle)) right=middle;
else left=middle;
}
return middle;
}
int main(int argc, char *argv[])
{
int t,i,j;
double r;
cin>>t;
while(t--)
{
cin>>n>>f;
for(max_area=-1,i=0;i<n;i++)
{cin>>r; area[i]=PI*r*r; max_area=max(max_area,area[i]); }
printf("%.4lf\n",binary());
}
return 0;
}
poj 3122 pie(二分搜索)
最新推荐文章于 2018-08-28 20:15:58 发布