Pie
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Description
My friends are 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 (but 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 be of the same size.
What is the largest possible piece size all of us can get? All the pies are cylindrical in shape and they all have the same height 1, but the radii of the pies can be different.
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 ≤ 10 000: the number of pies and the number of friends.
- One line with N integers ri with 1 ≤ ri ≤ 10 000: 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 can all get a pie piece of size V. The answer should be given as a floating point number with an absolute error of at most 10
−3.
Sample Input
3 3 3 4 3 3 1 24 5 10 5 1 4 2 3 4 5 6 5 4 2
Sample Output
25.1327 3.1416 50.2655
简单的一个二分查找,我却没想到二分查找也能这样来用,
用最大的蛋糕除以总人数作为底值 :l,所有蛋糕面积和除以总人数作为上面的值:r。(l+r)/2作为本次蛋糕的大小
如果这个蛋糕的大小使得能分到蛋糕的人少于总人数,让r等于中间值,否则让 l 等于中间值。
此题有坑,过生日的这个人本身也要算进去,
acos(-1.0);是精确表示3.1415926的值
输出的时候用%f 用%lf会精确度有误,小小的一个题,涨了这么多姿势。没白看。
代码就不写了。