C - Pie

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

3
3 3
4 3 3
1 24
5
10 5
1 4 2 3 4 5 6 5 4 2

Sample Output

25.1327
3.1416
50.2655


 #include<iostream>
#include<cmath>
using namespace std; const double pi=acos(-1.0);
const int maxn = ;
double a[maxn];
int n,k;
int solve(double x){
int sum=;
for(int i=;i<n;i++)
sum += (int)(a[i]*a[i]*pi/x);
if(sum >= k+) return ;
else return ;
} int main()
{
int t;
scanf("%d", &t);
while(t--){
scanf("%d %d", &n, &k);
double right = , left = , mid;
for(int i=; i<n; i++){
scanf("%lf", a+i);
if(a[i]*a[i]*pi > right) right = a[i]*a[i]*pi;
}
while(right - left > 1e-){
mid = (right + left)/;
if(solve(mid)) left = mid;
else right = mid;
}
printf("%.4lf\n",mid);
}
}

∏ = acos(-1.0)

二分-C - Pie的更多相关文章

  1. HDU 1969 精度二分

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  2. Pie(二分)

    ime Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8930   Accepted: 3235   Special Judge De ...

  3. 【二分答案】【POJ3122】【Northwestern Europe 2006】Pie

    Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10629   Accepted: 3744   Special Ju ...

  4. UVALive 3635 Pie 切糕大师 二分

    题意:为每个小伙伴切糕,要求每个小盆友(包括你自己)分得的pie一样大,但是每个人只能分得一份pie,不能拿两份凑一起的. 做法:二分查找切糕的大小,然后看看分出来的个数有没有大于小盆友们的个数,它又 ...

  5. HDU 1969 Pie(二分查找)

    Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...

  6. POJ - 3122 Pie(二分)

    http://poj.org/problem?id=3122 题意 主人过生日,m个人来庆生,有n块派,m+1个人(还有主人自己)分,问每个人分到的最大体积的派是多大,PS每 个人所分的派必须是在同一 ...

  7. HUD 1969:Pie(二分)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  8. Pie(浮点数二分)

    Pie http://poj.org/problem?id=3122 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2454 ...

  9. HDU 1969 Pie(二分,注意精度)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

随机推荐

  1. 字节码操作、javassist使用

    一.功能 1.动态生成新的类 2.动态改变某个类的结构(添加.删除.修改   新的属性.方法) 二.优势 1.比反射开销小,性能高 2.JAVAasist性能高于反射,低于ASM 使用javassis ...

  2. for循环嵌套练习题or99乘法表

    //输出1-10之间的和 public static void whileTest(){ //定义变量用于存储不断变化的和 int sum = 0; //定义变量,用于记录不断变化的被加数 int x ...

  3. js对象模型3

    3

  4. VMvare桥接网络连接不上解决办法

    记一次学习中的突发状况.由于本人的pc时长要在不同的网络中进行切换,ip地址一般都是不固定的,所以我使用虚拟机的时候一般使用的都是让VMvare自动识别网络环境.直到今天遇到一种突发情况,VMvare ...

  5. [MongoDB]MongoDB的ObjectId组成

    一.ObjectId的组成首先通过终端命令行,向mongodb的collection中插入一条不带“_id”的记录.然后,通过查询刚插入的数据,发现自动生成了一个objectId“5e4fa350b6 ...

  6. git 中文乱码配置

    $ git config --global --listuser.email=ibaiqi@163.comuser.name=zhangxui18n.commitencoding=utf-8i18n. ...

  7. CF594D REQ [离线+树状数组,欧拉函数]

    设 \[x = \prod_{i=1}^{cnt} p_i^{k_i} [p_i\in prime]\] 那么显然 \[\varphi(x) = x*\frac{1} {\prod_{i=1}^{cn ...

  8. 以下几种情况转换成布尔类型会得到false

    0 -0 '' NaN undefined null false document.all()

  9. STL入门学习中碰到的一些函数

    2020.02.10 fill #include<algorithm> vector<int> v{ 1, 2, 3, 3 }; fill(v.begin(), v.end() ...

  10. IDEA如何恢复到以前的代码

    虽然说IDEA的Ctrl+z撤销操作和Ctrl+Shift+Z重做操作为书写代码提供了很大的便利 但是在各种原因不小心失误撤销后又想不起来代码是怎么写的时候就非常尴尬,这时候就需要代码恢复到以前的状态 ...