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. BZOJ 2440: [中山市选2011]完全平方数( 二分答案 + 容斥原理 + 莫比乌斯函数 )

    先二分答案m,<=m的有m-∑(m/pi*pi)+∑(m/pi*pi*pj*pj)-……个符合题意的(容斥原理), 容斥系数就是莫比乌斯函数μ(预处理)... ----------------- ...

  2. jquery自动识别输入的都是数字

    //自动判断输入的书否为正整数 function wds_purchase_keyup(t) { var val = $(t).val(); -]+$/.test(val) && va ...

  3. jbpmAPI-8

    8.1. Process Instance State jBPM允许某些信息的持久性存储.本章描述了这些不同类型的持久性,以及如何配置它们.存储的信息的一个例子是运行时状态的过程.存储过程运行时状态是 ...

  4. 转 释一首美国民谣:沉默之音(The Sound Of Silence)

    Ask not what your country can do for you , ask what you can do for your country.    六十年代对美国而言是个多事之秋的 ...

  5. 原型扩展的方法解决IE和Firefox的Js兼容问题

    if(!document.all){//textContent->text    Element.prototype.__defineGetter__('text',function(){ret ...

  6. 基于SIM 卡卡基不同制作工艺的研究

    1 国内外现行的SIM 卡卡基制作工艺 SIM 卡由卡基和芯片两部分组成.卡基上有植入芯片的台阶式芯片槽,SIM 卡的芯片通过多点焊接植入台阶式芯片槽之中与卡基组成SIM 卡,然后经过个性化数据处理, ...

  7. 导入Excel加行公式和验证

    package com.sprucetec.tms.controller.fee.export; import com.sprucetec.tms.controller.base.BaseFeeExp ...

  8. poj2449 Remmarguts' Date【A*算法】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4303855.html   ---by 墨染之樱花 [题目链接]:http://poj.org/ ...

  9. javaweb学习路之一--web项目搭建

    概述: 工作闲暇时间想要自己搭建一个web项目玩玩,没想到大半天才弄了一个springMVC+mybatis的网站,简直菜的不行,以下记录所有的步骤加深印象 使用环境 1.jdk1.8 2.maven ...

  10. jvm的内存区域简介

    1.内存区域划分 jvm在执行java程序过程中会将管理的内存划分成若干不同的数据区域,他们分别是程序计数器,堆,方法区,虚拟机栈,本地方法栈. 1.1指令计数器 指令计数器是线程私有的,每个线程都有 ...