这里要注意这么几点:
1.人数要加上自己
2.不能直接对半径进行二分,因为所求的是体积最大值,应该对半径的平方进行二分~解的范围是在0到最大半径的平方之间
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include"cstdio" #include"cstring" #include"algorithm" #include"cmath" #define MAXN 10005 using namespace std; double num[MAXN]; double Pi=acos(-1.0); int n,m; bool judge(double x,int k) { int tail=n-1; while(k&&tail>=0) { double temp=num[tail]; while(temp-x>=0&&tail>=0&&k) {k--;temp-=x;} tail--; } if(!k) return true; return false; } int main() { int T; scanf("%d",&T); while(T--) { memset(num,0,sizeof(num)); scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { scanf("%lf",&num[i]); num[i]=num[i]*num[i]*Pi; } sort(num,num+n); double low=0.0,high=num[n-1],mid; while(high-low>=1e-6) { mid=low+(high-low)/2.0; if(judge(mid,m+1)) low=mid; else high=mid; } printf("%.4lf ",mid); } return 0; }