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 ≤ 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 volume V such that me and my friends can all get a pie piece of size V . The answer should be given as a oating 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

题目意思:有N个馅饼,要分给F+1个人。要求每个人分到的面积相同,求最大的面积是多少!(分的要求,每个人手上只能有一个馅饼.....馅饼可以分割)

解题思路:

1.题目的最终目的不外乎就是确定 一个最大的面积值。这个面积值得范围是0至所有馅饼面积之和sum...然后再想想,它要分给F+1个人,那么它的范围又缩小到了

0至sum/(F+1)。

     2.然后就想办法二分缩小范围,直到确定最大面积值。通过来判断分的实际个数t与F+1比较来二分。如果t>=F+1,说明要求的值在右边,否则在左边。(注意要有等于,不然输出相差太大)

     3.输出

程序代码:

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
const double pi = 4.0 * atan(1.0);
int n, f, r[];
double Left, Right;
void solve();
void input()
{
int T;
cin >> T;
while (T--)
{
cin >> n >> f;
f++;
for (int i = ; i <= n; i++)
cin >> r[i];
solve();
}
}
void solve()
{
Left = Right = ;
for (int i = ; i <= n; i++)
{
r[i] *= r[i];
if (r[i] > Right)
Right = r[i];
}
while (Right - Left > 1e-)
{
int tmp = ;
double mid = (Left + Right) / ;
for (int i = ; i <= n; i++)
tmp += r[i] / mid;
if (tmp >= f)
Left = mid;
else
Right = mid;
}
printf("%.4lf\n", Left * pi);
}
int main()
{
input();
return ;
}

HDU 1969(二分法)的更多相关文章

  1. hdu 1969 Pie (二分法)

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

  2. HDU 1969 Pie(二分法)

    My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...

  3. hdu 1969 Pie(二分查找)

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

  4. hdu 6288(二分法加精度处理问题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6288 题意:给出a,b,k,n可满足(n^a)*(⌈log2n⌉)^b<=k ,求最大的n值三个 ...

  5. HDU 1969 Pie(二分查找)

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

  6. hdu 1969(二分)

    题意:给了你n个蛋糕,然后分给m+1个人,问每个人所能得到的最大体积的蛋糕,每个人的蛋糕必须是属于同一块蛋糕的! 分析:浮点型二分,二分最后的结果即可,这里要注意圆周率的精度问题! #include& ...

  7. Pie(hdu 1969 二分查找)

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

  8. HDU 1969 Pie(二分搜索)

    题目链接 Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pi ...

  9. HDU 1969 Pie

    二分答案+验证(这题精度卡的比较死) #include<stdio.h> #include<math.h> #define eps 1e-7 ; double a[ff]; d ...

随机推荐

  1. selenium 学习笔记 ---新手学习记录(7) 问题总结(java)

    1.想要获取固定ul下所有li的个数  如下图: //获取ul下li的个数 List<WebElement> elements = driver.findElement(By.id(&qu ...

  2. Protel99Se使用方法详解

    Protel99SE是应用于Windows9X/2000/NT操作系统下的EDA设计软件,采用设计库管理模式,可以进行联网设计,具有很强的数据交换能力和开放性及3D模拟功能,是一个32位的设计软件,可 ...

  3. char[]转换成wchar_t的转换方法(GNU Libc规定wchar_t为32位)

    wchar_t是C/C++的字符数据类型,是一种扩展的字符存储方式,wchar_t类型主要用在国际化程序的实现中,但它不等同于unicode编码.unicode编码的字符一般以wchar_t类型存储. ...

  4. AnyEvent::HTTP 实现异步请求

    异步http: jrhmpt01:/root/async# cat a1.pl use LWP::UserAgent; use utf8; use DBI; use POSIX; use HTTP:: ...

  5. podoWeb极品流氓软件

    用firefox做页面网络性能测试, 打开网页就会发现页面不停的去请求googleapi.com上的jquery Or swfobject.js,页面就此卡住,一直在等待类似这两个请求的返回,知道Ab ...

  6. [Python]Unicode转ascii码的一个好方法

    写这篇文章的是一位外国人,他遇到了什么问题呢?比如有一个 Unicode 字符串他需要转为 ascii码: >>> title = u"Klüft skräms inför ...

  7. Never-build package 'XXXX' requires always-build package 'EhLib70'

    控件包使用了DbGridEh.Requies也加入了ehlib70.dcp就是编译时不通过,提示:      Never-build   package   'XXXX'   requires   a ...

  8. STC12C5201AD AD采样+串口发送模板

    #include<reg52.h> sfr ADC_CONTR = 0xBC; //ADC control register sfr ADC_RES = 0xBD; //ADC 8-bit ...

  9. Palindrome(Manacher)

    Palindrome Time Limit: 15000MS   Memory Limit: 65536K Total Submissions: 6183   Accepted: 2270 Descr ...

  10. [python网络编程]DNSserver

    在上一篇中,使用scrapy改动源IP发送请求的最后我们提到因为hosts文件不支持正则,会导致我们的随机域名DNS查询失败. 使用DNS代理服务器能够解决问题, 以下是我用gevent写的小工具.非 ...