分配派问题题目大意:
我要过生日了,准备了n个不同半径大小的圆形的pie,我有f 个朋友要来参加我的聚会,我要将pie公平分配,且给每人(包括我自己)分配一块尽量大的pie。(因为碎块看起来不上台面。)求分配每个人的pie的体积的最大值。(pie的厚度一定,等于1)
分析:
运用二分法:将每个人能分配到的pie最大体积区间一直二分,直到不满足条件:while(left+0.0001<right)。 体积区间为[left,right]。
Input:
One line with a positive integer: the number of test cases. Then for each test case:• One line with two integers N and F with 1 ≤ N, F ≤ 10000: the number of pies and the numberof friends.• One line with N integers ri with 1 ≤ ri ≤ 10000: the radii of the pies. Output:For each test case, output one line with the largest possible volume V such that me and my friends canall get a pie piece of size V . The answer should be given as a oating point number with an absoluteerror of at most 10−3。 案例输入输出:Sample Input:33 34 3 31 24510 51 4 2 3 4 5 6 5 4 2
Sample Output:25.13273.141650.2655
代码及步骤分析:
1 #include2 #include 3 #include 4 using namespace std; 5 const int m=10005; 6 double p[m]; 7 const double pi=acos(-1); 8 double max(double x,double y) 9 {10 if(x>=y)11 return x;12 else13 return y;14 }15 16 int main()17 {18 int t;19 scanf("%d",&t);20 while(t--)21 {22 int n,f,c,i;23 double sum=0, maxn=0;24 scanf("%d%d",&n,&f);25 f=f+1; // 人数需加上主人自己26 for(i=0;i