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.

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

Source

NWERC2006
 #include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int pi,pe,num;//pi是派的数量,pe是人的数量,num是可以分到的人数
double pie[];//pie的大小
double mi,ma,mid;//最少能分到的和最多能分到的,mid是二分法的中间变量
double pai=acos(-1.0);//pi的定义
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>pi>>pe;
pe++;//pe个朋友加上自己
ma=0.0;
mi=0.0;
for(int i=;i<pi;i++)
{
cin>>pie[i];
pie[i]=pai*pie[i]*pie[i];
ma+=pie[i];
if(pie[i]>mi)
mi=pie[i];
}
ma/=pe;
mi/=pe;
while(mi+0.00001<ma)//因为两个都是double型无法相等所以+0.0001控制
{
mid=(ma+mi)/;
num=;
for(int i=;i<pi;i++)
{
num+=(int)(pie[i]/mid);
}
if(num>=pe)mi=mid;//足够,往大继续二分
else ma=mid;//不够,往小继续二分
}
printf("%.4lf\n",mi);
}
return ;
}

HDU 1969 Pie(二分查找)的更多相关文章

  1. (step4.1.2)hdu 1969(Pie——二分查找)

    题目大意:n块馅饼分给m+1个人,每个人的馅饼必须是整块的,不能拼接,求最大的. 解题思路: 1)用总饼的体积除以总人数,得到每个人最大可以得到的V.但是每个人手中不能有两片或多片拼成的一块饼. 代码 ...

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

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

  3. HDU 1969 Pie [二分]

    1.题意:一项分圆饼的任务,一堆圆饼共有N个,半径不同,厚度一样,要分给F+1个人.要求每个人分的一样多,圆饼允许切但是不允许拼接,也就是每个人拿到的最多是一个完整饼,或者一个被切掉一部分的饼,要求你 ...

  4. hdu 1969 Pie(二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others)    Me ...

  5. 题解报告:hdu 1969 Pie(二分)

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

  6. 【hoj】2651 pie 二分查找

    二分查找是一个非常主要的算法,针对的是有序的数列,通过中间值的大小来推断接下来查找的是左半段还是右半段,直到中间值的大小等于要找到的数时或者中间值满足一定的条件就返回,所以当有些问题要求在一定范围内找 ...

  7. Can you find it? HDU - 2141 (二分查找)

    Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...

  8. HDU 1969 Pie【二分】

    [分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...

  9. hdu 1969 pie 卡精度的二分

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

随机推荐

  1. charles支持https抓包

    前言 最近发现访问项目的网页偶尔会被插入广告,很有可能是运营商劫持流量插入进去的,我在家里使用的长城宽带打开非加密的网页,时不时会弹个广告窗,这个也算是中国特色了.因此计划项目上线https,抓包分析 ...

  2. 【6】锋利的 jQuery 笔记

    1. 代码技巧 1. 利用 id, class 实现同级隐藏显示 效果如下: 2. 字体放大效果 效果图: 3. tab 切换 效果图: 4. 切换样式 添加 Cookie 效果图: 5. 编写插件 ...

  3. 启用div作为编辑器 添加contentEditalbe属性

    1.自从HTML5中新引入了contentEditalbe属性以后,div就与textarea一样,可以作为最常用的编辑器使用. 1.启用div作为编辑器 让div进入编辑状态很简单,只需要: 复制代 ...

  4. angularjs的directive详解

    Directive(指令)笔者认为是AngularJ非常强大而有有用的功能之一.它就相当于为我们写了公共的自定义DOM元素或CLASS属性或ATTR属性,并且它不只是单单如此,你还可以在它的基础上来操 ...

  5. 一步步优化JVM五:优化延迟或者响应时间

    本节的目标是做一些优化以满足对应用对延迟的需求.这次需要几个步骤,包括完善Java堆大小的配置,评估垃圾回收占用的时间和频率,也许还要尝试切换到不同的垃圾回收器,以及由于使用了不同的垃圾回收器,需要重 ...

  6. idea中建立maven web项卡在Generating Project in Batch mode

    Maven命令执行到Generating Project in Batch mode 卡住,原因是网络带宽不足问题!需要下载一个约5.1M的xml文件. Maven一般命令:mvn archetype ...

  7. 获取XMLHttpRequest对象

    //创建一个XMLHttpRequest对象 ,利用此对象与服务器进行通信 是AJAX技术的核心 /////////////////////////////////////////////////// ...

  8. linux重要命令

    echo echo命令用于在终端显示字符串或输出变量提取后的值,格式为:"echo [字符串 | $变量]". 将指定字符串输出到终端屏幕: [root@linuxprobe ~] ...

  9. VR应用向导,全球Top10 VR应用排行榜

    2016年国际知名产商索尼.三星.HTC.Oculus.YouTube等等都推出了自己的VR设备,与此同时还有自有的VR应用平台,供各位玩家下载应用体验沉浸式VR,当然每个平台的VR应用下载量各不相同 ...

  10. mozilla your firefox profile cannot be loaded. it may be missing or inaccessible

    check the permissions ls -l ~/.cache | grep mozilla fix the permissions sudo chown -R $USER:$USER ~/ ...