Pie
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10686 Accepted Submission(s): 3805
Problem Description
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though.
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.
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.
---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.141650.2655
--------------------------------------------------------------------------------------------------------------
/* 问题 C: Pie 题目描述 题意:作者要开一个生日party,他现在拥有n块高度都为1的圆柱形奶酪,已知每块奶酪的底面半径为r不等, 作者邀请了f个朋友参加了他的party,他要把这些奶酪平均分给所有的朋友和他自己(f+1人), 每个人分得奶酪的体积必须相等(这个值是确定的),形状就没有要求。现在要你求出所有人都能够得到的最大块奶酪的体积是多少? 要求是分出来的每一份必须出自同一个pie,也就是说当pie大小为3,2,1,只能分出两个大小为2的,剩下两个要扔掉。 输入 T组测试数据 1<=T<=100 n,f n块高度都为1的圆柱形奶酪,f个人 1 ≤ n,f ≤ 10 000 每块奶酪的底面半径为r, 1 ≤ ri ≤ 10 000 输出 现在要你求出所有人都能够得到的最大块奶酪的体积是多少?保留四位小数 样例输入 3 3 3 4 3 3 1 24 5 10 5 1 4 2 3 4 5 6 5 4 2 样例输出 25.1327 3.1416 50.2655 提示 PI = 3.1415926535897932; */ #include<stdio.h> #include<string.h> #include<algorithm> #define PI 3.1415926535897932 using namespace std; double v[10050]; int n,f; bool judge(double x) { int sum=0; for(int i=0;i<n;i++) { sum+=(int)(v[i]/x); } if(sum>=f) return true; return false; } double search(double k) { double left=0; double right=k; double mid; while(right-left>0.000001) { mid=(left+right)/2; if(judge(mid)) left=mid; else right=mid; } return mid; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&f); f++; int r; double max=-0x3f3f3f3f; memset(v,0,sizeof(v)); for(int i=0;i<n;i++) { scanf("%d",&r); v[i]=PI*r*r; if(v[i]>max) max=v[i]; } printf("%.4lf\n",search(max)); } return 0; }