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. 用Canvas,画中国国旗(Canvas基本知识点)

    .getContext("2d")=======>获取绘图接口 //2d .beginPath()========>创建绘图路径开始点 .moveTo(x,y)==== ...

  2. Spark-RDD/DataFrame/DateSet

    RDD 优点: 编译时类型安全编译时就能检查出类型错误 面向对象的编程风格直接通过类名点的方式来操作数据 缺点: 序列化和反序列化的性能开销无论是集群间的通信, 还是IO操作都需要对对象的结构和数据进 ...

  3. [UWP小白日记-7]转换MVA学院的XML字幕为SRT (二)

    瞎扯淡 上个版本,非常蠢用来N多的循环导致非常卡性能烂得不行,这次使用XmlDocument类来读取XML字幕 其实根本不用各种扒XML字幕,好吧我这是学习使用XmlDocument类,嗯就是这个样子 ...

  4. JAVA-代理学习一之JDK实现

    代理的实现依赖于反射,建议不太懂反射的童鞋先看看反射相关的知识点. 代理可以理解为对实际调用方法的一种能力的加强. 代理分为静态代理和动态代理: <1> 静态代理示例 接口MyInterf ...

  5. 使用Egret Conversion 转化as代码到ts代码

    1,转换时,如果一次转化代码文件太多,可能会出现错误,可以一次少转几个文件: 2,如果出现所转换文件中有错误,则需修改要转换文件: 3,转换时还可能生成新文件夹如elex,转换的ts文件就会存在ele ...

  6. C# 操作IIS -App & AppPools

    using System; using System.DirectoryServices; using System.Management; using Microsoft.Web.Administr ...

  7. 手动为maven的本地仓库添加JAR

    在要添加的jar所在的文件夹下打开黑屏 如添加Oracle的ojdbc6.jar 输入: mvn install:install-file -DgroupId=com.oracle -Dartifac ...

  8. .net XML操作

    一.常规介绍 //初始化一个xml对象 XmlDocument xml = new XmlDocument(); //加载xml文件 xml.Load("文件路径"); //读取指 ...

  9. asp.net时间范围查询

    1.首先要查询类表中的一个时间段,要明确我的数据库中只有一个时间字段,我们先将他拆分一下. if ($("#news_OpenTime").val() != "" ...

  10. 连接到sql server 2008 TCP、IP出错

    1.点击 开始 --> 所有程序 --> Microsoft SQL Server2008 --> 配置工具-->SQL Server  configuration Manag ...