Problem Descriptionmy birthday is coming up and traditionally I ' m serving pie. Not just one pie, no, I had a number N of them, of various tastes and of various sizes. F of my friends is coming to my party and each of the them gets a piece of pie. This should is one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though.
My Friends is very annoying and if one of them gets a bigger piece than the others, they start complaining. Therefore all of them should get equally sized (and not necessarily equally shaped) pieces, even if this leads to some pie Getting spoiled (which is better than spoiling the party). Of course, I want a piece of pie for myself too, and that piece should also is of the same size.
What's the largest possible piece size all of us can get? All the Pies is cylindrical in shape and they all has the same height 1, but the radii of the Pies can is different. Inputone line with a positive integer:the number of test cases. Then to each test case:
---One line with a integers n and F with 1 <= N, F <= 000:the number of pies and the number of friends.
---one line with N integers ri with 1 <= ri <= 000:the radii of the Pies. Outputfor each test case, output one line with the largest possible volume V such this me and my friends can all get a pie Piece of Size v. The answer should is given as a floating point number with an absolute error of in 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
SourceNWERC2006
1#include <iostream>2#include <stdio.h>3#include <cmath>4 using namespacestd;5 intPi,pe,num;//Pi is the number of pies, PE is the number of people, NUM is the number that can be divided into6 Doublepie[10005];//the size of pie7 DoubleMi,ma,mid;//The least can be divided and the most can be divided, mid is the dichotomy of the middle variable8 DoublePai=acos (-1.0);//the definition of pi9 intMain ()Ten { One intT; ACin>>T; - while(t--) - { theCin>>pi>>PE; -pe++;//pe a friend plus own -Ma=0.0; -Mi=0.0; + for(intI=0; i<pi;i++) - { +Cin>>Pie[i]; Apie[i]=pai*pie[i]*Pie[i]; atma+=Pie[i]; - if(pie[i]>mi) -Mi=Pie[i]; - } -Ma/=PE; -Mi/=PE; in while(mi+0.00001<MA)//because two of them are double type and cannot be equal, so +0.0001 controls - { toMid= (MA+MI)/2; +num=0; - for(intI=0; i<pi;i++) the { *num+= (int) (pie[i]/mid); $ }Panax Notoginseng if(NUM>=PE) Mi=mid;//enough to continue the two points to large - ElseMa=mid;//not enough, go to the small continue two points the } +printf"%.4lf\n", MI); A } the return 0; +}
HDU 1969 Pie (two-point search)