poj 3122 Pie
来源:互联网 发布:凡科互动 游戏源码 编辑:程序博客网 时间:2024/06/07 03:29
Pie
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 15340 Accepted: 5244 Special Judge
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.
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
33 34 3 31 24510 51 4 2 3 4 5 6 5 4 2
Sample Output
25.13273.141650.2655
Source
Northwestern Europe 2006
提示
题意:
在我的生日派对上准备了n(1<=n<=10000)个派,有f(1<=f<=10000)个朋友会参加我的派对。但他们很烦(jiao)人(qing),如果有人的派比其他人的大,他们会很不爽,所以要保证每个人都是平均分配,即使有多余的也要如此。每个派大小不一,但都是高度为1的圆柱体,给出每个派的半径,每个人最大能有多少派?
思路:
做了那么多,原来二分是这样用的。
0做下界,最大那一块完整的派做上界, 用能分到的人数去做比较可以使误差比较小,如果以分的体积去算误差可能比较大(反正我连样例都过不了)。
示例程序
Source CodeProblem: 3122Code Length: 798BMemory: 396KTime: 16MSLanguage: GCCResult: Accepted#include <stdio.h>#define PI 3.14159265359int main(){ int t,i,n,f,i1,a[10000],sum; double num,l,m,r; scanf("%d",&t); for(i=1;t>=i;i++) { scanf("%d %d",&n,&f); f++; l=0; r=0; for(i1=0;n>i1;i1++) { scanf("%d",&a[i1]); a[i1]=a[i1]*a[i1];//每个派的体积 if(r<a[i1]) { r=a[i1];//寻找上界 } } while(r-l>=1e-4) { m=(l+r)/2; sum=0; for(i1=0;n>i1;i1++) { sum=sum+a[i1]/m; } if(sum<f)//m选大了,分到的人少 { r=m; } else//m选小了,还可以每个人再分点或者刚好合适 { l=m; } } printf("%.4f\n",m*PI);//π在输出里乘进去就行了 } return 0;}
0 0
- POJ-3122 Pie
- POJ 3122 Pie 二分
- POJ 3122 Pie 二分
- poj 3122 pie
- POJ 3122 Pie
- poj 3122 la3635 pie
- POJ 3122 Pie
- POJ-3122-Pie
- POJ 3122 Pie
- POJ 3122 Pie
- poj 3122 Pie
- poj 3122 pie
- POJ 3122 Pie
- POJ-3122 Pie
- POJ 3122--Pie
- POJ 3122Pie
- poj 3122 Pie (二分)
- POJ - 3122 Pie
- jquery grid表格checkbox的关联勾选与取消
- 使用thinkphp+dwz博客总结
- 2818: Gcd
- Java获取当前日期时间
- 抛弃mysql模糊查询,使用sphinx做专业索引
- poj 3122 Pie
- Interpolation Tricks
- 大数据量的算法面试题
- printf 的宏定义版本
- CSS3 box-shadow
- 数据结构实验之查找四:二分查找
- C# ListView控件的item项目实现全选与取消
- Bootstrap学习(三)——Bootstrap 插件
- zabbix系列(六)zabbix添加对ubuntu系统的监控