2006 ACM Northwestern European Programming Contest C题(二分求最大)
来源:互联网 发布:大数据龙头公司 编辑:程序博客网 时间:2024/05/22 04:35
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a numberN 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 ≤ 10000: the number of pies and the number of friends.
- One line with N integers ri with 1 ≤ri ≤ 10000: the radii of the pies.
Output
For each test case, output one line with the largest possible volumeV such that me and my friends can all get a pie piece of sizeV. 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
#include <iostream>#include <cmath>using namespace std;#define MAX(a, b) ((a) > (b) ? (a) : (b)) const int maxn = 10010;const double PI = acos(-1.0);double s[maxn];int n, f, r;int ok(double x){int sum = 0;for (int i = 0; i < n; i++) sum += floor(s[i] / x);return sum >= f + 1;}int main(){int T;cin>>T;while (T--){cin>>n>>f;double max = -1;//找最大圆的面积for (int i = 0; i < n; i++){cin>>r;s[i] = PI * r * r;max = MAX(max, s[i]);}//二分找最大double L = 0, R = max;while (R - L > 1e-5){double M = (L + R) / 2;if (ok(M)) L = M;else R = M;}printf("%.5lf\n", L);}return 0;}
- 2006 ACM Northwestern European Programming Contest C题(二分求最大)
- C-Cleaning Pipes(判断两线段相交+二分图判定) 2015-2016 Northwestern European Regional Contest (NWERC 2015)
- 2015-2016 Northwestern European Regional Contest (NWERC 2015) 补题
- 2013-2014 Northwestern European Regional Contest (NWERC 2013)
- 2015-2016 Northwestern European Regional Contest (NWERC 2015) E
- 2015-2016 Northwestern European Regional Contest (NWERC 2015)
- 2001-2002 ACM Northeastern European Regional Programming Contest-Problem G-"Library"
- HDU/HDOJ 1551 Cable master 2001-2002 ACM Northeastern European Regional Programming Contest
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016)
- 2015-2016 Northwestern European Regional Contest (NWERC 2015) 7/11 待补
- 2015-2016 Northwestern European Regional Contest 训练总结 【5+2】【待补】
- 2012-2013 Northwestern European Regional Contest (NWERC 2012)【solved:6 / 11】
- 2014-2015 Northwestern European Regional Contest (NWERC 2014)【solved:7 / 11】
- 2015-2016 Northwestern European Regional Contest I.Identifying Map Tiles(超级技巧+脑洞)
- 2015-2016 Northwestern European Regional Contest (NWERC 2015) E. Elementary Math
- [bzoj2557][Poi2011]Programming Contest 二分图最大匹配
- Gym 101334(ACM ICPC 2005–2006, Northeastern European Regional Contest)
- 2013-2014 ACM ICPC Central European Regional Contest (CERC 13) K题(dp)
- 作用域链(scope chain)和原型链(prototype chain)
- 数据结构 线性表 建立循环链表
- sqoop 导入数据特殊字符问题
- 開國時代
- kernel density estimation-核密度估计
- 2006 ACM Northwestern European Programming Contest C题(二分求最大)
- 成绩3
- 数据结构 线性表 循环链表 插入与删除
- Android 4.0 事件输入(Event Input)系统
- A转a
- 密码翻译
- 线段树专辑
- 北間島移住
- 第三章 操作符