hdu1969 Pie (二分)
来源:互联网 发布:matlab模拟退火算法 编辑:程序博客网 时间:2024/05/29 17:15
Pie
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7202 Accepted Submission(s): 2699
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
33 34 3 31 24510 51 4 2 3 4 5 6 5 4 2
Sample Output
25.13273.141650.2655
Source
NWERC2006
Recommend
wangye | We have carefully selected several similar problems for you: 1551 2446 2298 2333 1399
解析:圆周率不精确导致wa!==》 pi=3.14159265358979323846 AC。
基本思路,二分枚举每个人分到的蛋糕面积,然后验证验证n份蛋糕分成的份数能否大于等于f+1(我也要一份的)。
代码:
#include<cstdio>#include<algorithm>using namespace std;const int maxn=1e4;const double pi=3.14159265358979323846;const double precision=1e-6;int n,f;double s[maxn+10];bool ok(double x){ int i,sum=0; for(i=1;i<=n;i++)sum+=(int)(s[i]/x); return sum>=f;}int main(){ freopen("1.in","r",stdin); int t,i; double l,r,mid; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&f),f++; for(i=1;i<=n;i++) { scanf("%lf",&s[i]); s[i]=pi*s[i]*s[i];} l=0,r=s[1]; for(i=2;i<=n;i++)r=max(r,s[i]); while(r-l>=precision) { mid=(l+r)/2; if(ok(mid))l=mid; else r=mid;} printf("%.4lf\n",l);} return 0;}
0 0
- hdu1969 Pie (二分)
- HDU1969:Pie(二分 + 贪心)
- hdu1969 Pie 二分
- hdu1969(pie二分)
- HDU1969---Pie 二分
- HDU1969:Pie(二分)
- 二分查找 hdu1969 pie
- hdu1969 Pie 二分
- HDU1969 PIE 二分查找
- hdu1969 Pie(二分答案)
- HDU1969 Pie(二分搜索)
- hdu1969 pie【二分】
- HDU1969:Pie(二分)
- Hdu1969-Pie-【二分】
- poj 3122&&hdu1969 Pie(二分)
- 【hdu1969】Pie——二分
- 【HDU1969】Pie(二分法)
- hdu1969 Pie
- java开发俄罗斯方块学习笔记 Day-1 分析
- 被需要,才是最极致的幸福
- Android酷炫实用的开源框架(UI框架)
- [Chromium学习笔记]了解Chromium的基础知识
- python操作mysql数据库
- hdu1969 Pie (二分)
- IOS-45-登录页面相关设置之手机号(只显示数字键盘、只允许输入数字、只允许输11位数)
- Gethibernatetemplate的find方法大全
- OC-035.协议
- 关于win10能上qq不能联网的问题解决方案之一
- HYSBZ - 1036 树的统计
- C语言实现线性顺序链表
- jQuery选择器总结
- 由动态库文件dll生成lib库文件