主要是二分,在加上一点点贪心的思想。每个人分到的派只能来自于同一个派
eps取太小会tle,0.001就够了,倒是PI必须很精确,不然wa,可惜我只背的到3.1415926。。。win7计算器里的派:3.1415926535897932384626433832795
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAX 10010
#define PI 3.141592653589793238462
#define EPS 0.0001
using namespace std;
double s[MAX];
int main()
{
int t,n,f,i,j,piece;
double front,rear,all,help;
scanf("%d",&t);
while(t--)
{
all=0;
scanf("%d %d",&n,&f);<pre name="code" class="cpp"><span style="white-space:pre"> </span>f++;
for(i=0;i<n;i++) { scanf("%lf",&s[i]); s[i]=PI*s[i]*s[i]; all+=s[i]; } front=EPS,rear=all/f; while(rear-front>EPS) { piece=0; help=(front+rear)/2; for(i=0;i<n;i++) piece+=int(s[i]/help); if(piece>f) front=help; else rear=help; } printf("%.4lf\n",front); } return 0;}