Pie(二分法)
来源:互联网 发布:kcs洗发水怎么样知乎 编辑:程序博客网 时间:2024/05/29 12:25
Link:https://cn.vjudge.net/contest/173312#problem/B
题目:
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
33 34 3 31 24510 51 4 2 3 4 5 6 5 4 2
Sample Output
25.13273.141650.2655
Code:
#include<cstdio>#include<cstdlib>#include<iostream>#include<cmath>#include<cstring>#include<algorithm>#include<stack>#include<queue>#define pi acos(-1.0)using namespace std;double s[10010];double sum,maxx;int main(){ int t,i,f,n,cnt; double l,r,mid; scanf("%d",&t); while(t--) { sum=maxx=0; scanf("%d%d",&n,&f); f++; for(i=0;i<n;i++) { scanf("%lf",&s[i]); s[i]=pi*s[i]*s[i]; maxx=max(s[i],maxx); sum+=s[i]; } l=maxx/f; r=sum/f; while(r-l>0.00001) { cnt=0; mid=(l+r)/2; for(i=0;i<n;i++) cnt+=(int)(s[i]/mid); if(cnt>=f) l=mid; else r=mid; } printf("%.4lf\n",l); }return 0;}
- Pie (二分法)
- (POJ3122)Pie <二分法>
- Pie(二分法)
- 【HDU1969】Pie(二分法)
- uva - 12097 - Pie(二分法)
- poj 3122 Pie(二分法)
- 二分法-Pie
- 二分法--Pie
- 杭电oj1969 pie(二分法)
- hdu 1969 Pie (二分法+贪心)
- poj3122 Pie 二分法
- PIE(二分法分饼)
- HDU 1969:Pie【二分法】
- hdoj 1969 pie【二分法】
- HD1969 Pie【二分法】
- Pie(poj 3122)二分法
- Pie--hdu1969(二分法)
- HDU-1969 PIE 二分法
- HTML+Servlet + MVC + JDBC + MySQL的简单登录
- 非gui方式配置weblogic数据源和部署war
- 一棵树是否是另一棵树的子树问题
- 欢迎使用CSDN-markdown编辑器
- mfc richedit 自动换行
- Pie(二分法)
- 开始编写阅读jdk源码的文章
- LNMP环境下部署lepus3.7版本
- Fire Game (双起点bfs)
- html的文本元素
- C/C++ | 25-16 实现子串定位int FindSubStr
- I2C总线协议的verilog实现
- 使用Tinker与极光推送实现Android热更新
- 【Java并发编程】活性