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.输出

程序代码:

  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <algorithm>
  5. using namespace std;
  6. const double pi = 4.0 * atan(1.0);
  7. int n, f, r[];
  8. double Left, Right;
  9. void solve();
  10. void input()
  11. {
  12. int T;
  13. cin >> T;
  14. while (T--)
  15. {
  16. cin >> n >> f;
  17. f++;
  18. for (int i = ; i <= n; i++)
  19. cin >> r[i];
  20. solve();
  21. }
  22. }
  23. void solve()
  24. {
  25. Left = Right = ;
  26. for (int i = ; i <= n; i++)
  27. {
  28. r[i] *= r[i];
  29. if (r[i] > Right)
  30. Right = r[i];
  31. }
  32. while (Right - Left > 1e-)
  33. {
  34. int tmp = ;
  35. double mid = (Left + Right) / ;
  36. for (int i = ; i <= n; i++)
  37. tmp += r[i] / mid;
  38. if (tmp >= f)
  39. Left = mid;
  40. else
  41. Right = mid;
  42. }
  43. printf("%.4lf\n", Left * pi);
  44. }
  45. int main()
  46. {
  47. input();
  48. return ;
  49. }

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. Google地图,Baidu地图数据供应商

    http://janwen.iteye.com/blog/488659 Google百度  我老以为百度,Google的地图产品是自己开发的,原来是别人提供的数据, 百度的数据提供商有 北京世纪高通科 ...

  2. java ee环境搭建

    1.安装java(tm)2 platform 2.下载安装Java EE SDK 版本:Java Platform,Enterprise Edition 7 SDK (with JDK 7u45) 下 ...

  3. IOS 特定于设备的开发:Info.plist属性列表的设置

    应用程序的Info.plist属性列表使你能够在向iTunes提交应用程序时指定应用程序的要求.这些限制允许告诉iTunes应用程序需要哪些设备特性. 每个IOS单元都会提供一个独特的特性集.一些设备 ...

  4. 关于Qt信号与槽机制的传递方向性研究(结论其实是错误的,但是可以看看分析过程)

    最近由于项目的需求,一直在研究Qt.信号与槽机制是Qt的一大特色,该机制允许两者间传递参数,依次来实现对象间的通信.这个参数会分别存在于信号的参数列表和槽函数的参数列表中.需要注意的是,若将槽函数绑定 ...

  5. Delphi中的“委托”

    .NET中有委托(Delegate)的概念,其声明形式如下所示:     public delegate void MyDelegate(int aIntParam, string aStringPa ...

  6. python 启动简单web服务器

    有时我们在开发web静态页面时,需要一个web服务器来测试. 这时可以利用python提供的web服务器来实现. 1.在命令行下进入某个目录 2.在该目录下运行命令: python -m Simple ...

  7. HDU 2501 Tiling_easy version

    递推式:f[n]=2*f[n-2]+f[n-1] #include <cstdio> #include <iostream> using namespace std; ]; i ...

  8. c#简单的调试信息、日志信息输出

    public static void ErrorLog(string mssg) { string FilePath = "D:/logs/ErrorLog.txt"; try { ...

  9. SharePoint 2010以其他用户身份登录的弹出代码

    在SharePoint 2010平台中,可以在当前用户登录系统的情况下使用其他用户身份登录,以达到在同一浏览器中切换用户身份的目的. 每个用户登录SharePoint系统之后都会在系统右上角将用户的名 ...

  10. NSOperationQueue和GCD的区别

    使用NSOperationQueue用来管理子类化的NSOperation对象,控制其线程并发数目.GCD和NSOperation都可以实现对线程的管理,区别是 NSOperation和NSOpera ...