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. O2O外卖玩众包 开放平台难解标准之痛

    开放平台难解标准之痛" title="O2O外卖玩众包 开放平台难解标准之痛">  有一种怪现象一直是国内互联网企业摆脱不了的附骨之疽--不管规模大小,总是削尖了脑 ...

  2. STT-MRAM存在的两个弊端

    随着自旋转移矩效应的发现以及材料和结构的优化,基于自旋转移矩效应的STT-MRAM器件应运而生.自从自旋转移矩效应被证实以来,一方面研究人员通过大量的努力尝试降低磁化反转的临界电流,增加热稳定性:另一 ...

  3. 桌面粉笔功能.有window ink功能区开启的快捷键

    功能区开启的快捷键 方法1: win+W唤出工作区,可以直接点击,但是没有快捷键.prtsc是直接截取屏幕(国际通用)然后在画图打开或直接粘贴于某处都可以. 方法2:快捷键是 Windows 徽标键 ...

  4. opencv —— getTickCount、getTickFrequency 计时函数

    getTickCount 函数 返回 CPU 自某个事件(如启动电脑)以来走过的时钟周期数. getTickFrequency 函数 返回 CPU 一秒钟所走过的时钟周期数. 二者结合使用,可以用来计 ...

  5. 第3章 关系数据库标准语言SQL(重点) | 数据库知识点整理

    第3章 关系数据库标准语言SQL(重点) 了解 SQL语言发展过程 关系数据库技术和关系数据库管理系统RDBMS产品的发展过程 掌握 SQL语言的特点和优点 面向过程的语言和SQL语言的区别 关系数据 ...

  6. <a>超链接标签,<button>按钮标签,实现返回跳转

    超链接: <a href=”#” onClick=”javascript :history.back(-1);”>返回上一页</a> <a href=”#” onClic ...

  7. 图片上传的进度条-jquery

    <div style="padding: 10px;"> <div class="progress-bar" style="disp ...

  8. 使用 VMware Workstation Pro 安装新的虚拟机

     一.连接服务器 (1)“文件”右键 (2)输入用户名.密码连接服务器 二.创建新的虚拟机 (1) (2) (3) (4) (5) (6) (7) (8)  三.配置服务器 配置文档 - 链接:htt ...

  9. Navicat Premium15安装与激活(破解)

    Navicat premium是一款数据库管理工具,是一个可多重连线资料库的管理工具,它可以让你以单一程式同时连线到 MySQL.SQLite.Oracle 及 PostgreSQL 资料库,让管理不 ...

  10. 连接数据库的工具JdbcUtil

    public class JdbcUtil { private static String driver=null;//驱动 private static String url=null;//连接地址 ...