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

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

Sample Output

  1. 25.1327
  2. 3.1416
  3. 50.2655

Source

NWERC2006
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<cmath>
  4. using namespace std;
  5. int pi,pe,num;//pi是派的数量,pe是人的数量,num是可以分到的人数
  6. double pie[];//pie的大小
  7. double mi,ma,mid;//最少能分到的和最多能分到的,mid是二分法的中间变量
  8. double pai=acos(-1.0);//pi的定义
  9. int main()
  10. {
  11. int T;
  12. cin>>T;
  13. while(T--)
  14. {
  15. cin>>pi>>pe;
  16. pe++;//pe个朋友加上自己
  17. ma=0.0;
  18. mi=0.0;
  19. for(int i=;i<pi;i++)
  20. {
  21. cin>>pie[i];
  22. pie[i]=pai*pie[i]*pie[i];
  23. ma+=pie[i];
  24. if(pie[i]>mi)
  25. mi=pie[i];
  26. }
  27. ma/=pe;
  28. mi/=pe;
  29. while(mi+0.00001<ma)//因为两个都是double型无法相等所以+0.0001控制
  30. {
  31. mid=(ma+mi)/;
  32. num=;
  33. for(int i=;i<pi;i++)
  34. {
  35. num+=(int)(pie[i]/mid);
  36. }
  37. if(num>=pe)mi=mid;//足够,往大继续二分
  38. else ma=mid;//不够,往小继续二分
  39. }
  40. printf("%.4lf\n",mi);
  41. }
  42. return ;
  43. }

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. CSS多列、用户界面属性

    CSS多列 常用属性: column-count 分几列 column-gap 列间距 column-rule 列分割线的样式(写法和border一样) 例如: 一个div分三列,列之间间距为10px ...

  2. Oracle sql执行计划

    explain plan     explain plan for sql_statement     select * from table(dbms_xplan.display) DBMS_XPL ...

  3. CodeForces 645A Amity Assessment

    简单模拟. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #incl ...

  4. php学习笔记——语言切换

    现在的网站很多都可以实现多语言,于是记录一下多语言的实例. 方法一:通过将所有显示在页面的字段放在一个message文件里面来实现 思路如下图: test代码: main.php: <?php ...

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

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

  6. hdu5976贪心乘法逆元

    hdu 5976 Detachment题目连接 题意: 给定一个自然数x,让你给出一种拆分方式n=a1+a2+...(ai≠aj),使得每个小部分的乘积s=a1*a2*...最大 解题思路: 我们要乘 ...

  7. Chapter 2 Open Book——32

    I paused for a long moment, and then made the mistake of meeting his gaze. 我停顿了很长时间,然后错误的去对视了他的凝视 我停 ...

  8. Python学习笔记——进阶篇【第九周】———协程

    协程 协程,又称微线程,纤程.英文名Coroutine.一句话说明什么是协程:协程是一种用户态的轻量级线程. 协程拥有自己的寄存器上下文和栈.协程调度切换时,将寄存器上下文和栈保存到其他地方,在切回来 ...

  9. NodeJs md5 sha1加密

    var crypto = require('crypto');module.exports = {  md5: (str)=> {    return crypto.createHash('md ...

  10. Angular JS Scope(作用域)

    Scope(作用域) 是应用在 HTML (视图) 和 JavaScript (控制器)之间的纽带. Scope 是一个对象,有可用的方法和属性. Scope 可应用在视图和控制器上. 当你在 Ang ...