Pie (二分)
来源:互联网 发布:电装机器人编程 编辑:程序博客网 时间:2024/06/05 10:13
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:<ul><li>One line with two integers N and F with 1 ≤ N, F ≤ 10 000: the number of pies and the number of friends.<li>One line with N integers ri with 1 ≤ ri ≤ 10 000: the radii of the pies.</ul>
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<sup>3</sup>.
Sample Input
33 34 3 31 24510 51 4 2 3 4 5 6 5 4 2
Sample Output
25.13273.141650.2655
题目大概:
分饼。
思路:
二分。
代码:
#include <iostream>#include <cmath>#include <cstdio>using namespace std;const double e=acos(-1.0);double t,n,f,sum,ma; double a[10500];int main(){ cin>>t; for(int i=1;i<=t;i++) { sum=0; cin>>n>>f; for(int j=1;j<=n;j++) { cin>>a[j]; a[j]=a[j]*a[j]; ma=max(ma,a[j]); } double l,r,mid; l=0;r=ma; while(fabs(r-l)>1e-6) { mid=(l+r)/2; int k=0; for(int j=1;j<=n;j++) k+=(int)(a[j]/mid); if(k>=f+1) { l=mid; } else { r=mid; } } printf("%.4f\n",mid*e); } return 0;}
阅读全文
0 0
- PIE(二分)
- 12097 - Pie (二分)
- hdu1969 Pie (二分)
- Pie(二分)
- poj_3122 Pie(二分)
- #POJ3122#Pie (二分)
- Pie (二分)
- Pie (二分)
- POJ3122 Pie(二分)
- POJ 3122 Pie(二分)
- HDU:1969 Pie (二分)
- HDOJ 1969 Pie(二分)
- 【HDU】-1969-Pie(二分)
- (二分)HDU 1969 pie
- UVALive 3635 Pie (二分)
- UVALive - 3635 - Pie(二分)
- POJ 3122 Pie (二分)
- HDU1969:Pie(二分 + 贪心)
- 原表达式转换为后缀表达式
- equals 和 == 的区别
- 深入理解Spring系列之七:web应用自动装配Spring配置
- WAMP的apache无法启动DocumentRoot must be a directory
- (吴恩达笔记 2-1)——支持向量机SVM
- Pie (二分)
- 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 (多重背包 动态规划)
- ACM训练日记—8月10日
- nlp中的LSTM学习
- Java反射
- Java web学习笔记之servlet技术
- 单调队列学习
- 编辑距离问题
- HDU 6103 Kirinriki【尺取法】【思维题】【好题】