分蛋糕
来源:互联网 发布:京东面试题java 编辑:程序博客网 时间:2024/04/27 14:15
/*
题意:作者要开一个生日party,他现在拥有n块高度都为1的圆柱形奶酪,已知每块奶酪的底面半径为r不等,
作者邀请了f个朋友参加了他的party,他要把这些奶酪平均分给所有的朋友和他自己(f+1人),
每个人分得奶酪的体积必须相等(这个值是确定的),形状就没有要求。
现在要你求出所有人都能够得到的最大块奶酪的体积是多少?
要求是分出来的每一份必须出自同一个pie,也就是说当pie大小为3,2,1,只能分出两个大小为2的,
剩下两个要扔掉。
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.
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
*/
思路:
分出来的每一份只能出自一个蛋糕,那么分的蛋糕大小一定不能超过最大那个蛋糕的体积。所以二分在(0,max);
#include<stdio.h>#include<string.h>#define PI 3.1415926535897932double s[1500],max;int n,f;double bsearch(){ double l,r,mid; int ans,i; l=0; r=max; while(r-l>0.000001) { ans=0; mid=(l+r)/2; for(i=0;i<n;i++) { ans=ans+(int)(s[i]/mid); } if(ans>=f+1) { l=mid; } else { r=mid; } } return r; }int main(){ int t,r,i; scanf("%d",&t); while(t--) { max=0; memset(s,0,sizeof(s)); scanf("%d%d",&n,&f); for(i=0;i<n;i++) { scanf("%d",&r); s[i]=PI*r*r; if(s[i]>max) { max=s[i]; } } printf("%.4lf\n",bsearch()); } return 0; }
0 0
- 分蛋糕
- 分蛋糕
- 分蛋糕
- 分蛋糕
- 分蛋糕
- 分蛋糕
- 分蛋糕
- 分蛋糕的智慧
- 分蛋糕问题
- OpenJudge_P6047 分蛋糕(DP)
- 二分法(分蛋糕)
- 分蛋糕问题
- Assign Cookies(分蛋糕)
- CCF201703-1 分蛋糕
- 201703-1 分蛋糕
- ccf练习题分蛋糕
- CCFCSP201703-1分蛋糕
- (JAVA)分蛋糕
- Android设计模式源码解析之责任链模式
- 杨辉三角形
- Android 之权限以及configChanges配置
- MAKEWORD(2,2)使用
- jsp页面中的代码加载执行顺序
- 分蛋糕
- GUI与UI的区别
- hdoj 1576 A/B [扩展欧几里得.逆元]
- 遍历文件夹中的文件(以图片为例)
- Web应用设置统一错误友好界面
- Android Camera的使用 (一)
- POJ3349——Snowflake Snow Snowflakes
- 使用C++类的成员函数来做windows的窗口函数
- refresh的停车场