题目链接:https://vjudge.net/problem/POJ-3122
精度二分题,注意不要二分半径,因为分开的每块蛋糕可以是不同形状的,不一定非得是圆柱形
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#define eps 1e-6
#define pi 3.141592653589
#define INF 0x3f3f3f3f
using namespace std;
const int N = 10010;
double a[N];
int T,pie,people;
bool check(double x)
{
int cnt=0;
for(int i=0;i<pie;i++)
{
int num = int(a[i]/x);
cnt+=num;
}
if(cnt>=people) return true;
return false;
}
int main()
{
scanf("%d",&T);
while(T--)
{
double maxx = -INF;
scanf("%d%d",&pie,&people);
double sum = 0;
for(int i=0;i<pie;i++)
{
scanf("%lf",&a[i]);
//sum+=a[i];
a[i] = pi*a[i]*a[i];
maxx = max(maxx,a[i]);
}
people++;
double l = 0;
double r = maxx;
while(r-l>eps)
{
double mid = (l+r)/2;
if(check(mid)) l=mid;
else r = mid;
}
double ans = l;
printf("%.4lf\n",ans);
}
return 0;
}