hdoj 1969 Pie
2015-08-19 21:23
393 查看
Pie
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6672 Accepted Submission(s): 2526
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.
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 二分:#include<stdio.h> #include<math.h> #define PI acos(-1.0) int a[10005]; int pn,fn,sum; int f(double x) { int i; sum=0; for(i=0;i<pn;i++) { sum+=(int)(a[i]*a[i]*PI/x);//是否满足最大 } return sum>=fn+1;//且满足人数 } int main() { int n; scanf("%d",&n); while(n--) { int i; sum =0; scanf("%d%d",&pn,&fn); for(i=0;i<pn;i++) { scanf("%d",&a[i]); } double left=0,right=315000000000.0,mid;//二分求面积 while(right-left>=1e-7) { mid=(right+left)/2; if(f(mid)) left=mid; else right=mid; } printf("%.4f\n",right); } }
相关文章推荐
- 小比赛(CodeForces 560A,UVA 11040,CodeForces 550B,HDU 1856,UVA 1644,CodeForces 560B,HDU 3405,UVA 10820)
- java 设计类时考虑多线程安全
- Myeclipse 10 破解说明
- 使用VS2010连接MySQL
- 数据持久化 将数据写入到本地 文件管理
- USB引脚定义以及导线的颜色定义
- ACM 概率&&动态规划
- 四校联赛
- PHP:echo print var_dump()和print_r()的区别
- System.getProperty("user.dir"); 获得系统属性
- MyBatis 关联查询
- 位运算 实现加法
- 汇编世界当中过程的经典
- 相遇~~~~
- undefined reference to `pthread_create'的错误。
- 不用加减乘除做加法题目:写一个函数,求两个整数之和
- 活不出自己,哪有什么情?
- hdoj1951
- InnoSetup快速入门(四):创建桌面快捷方式并作为可选的附加任务
- poj 1734