ime Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8930   Accepted: 3235   Special Judge

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 题意:过生日,有f+1个人(加上主人),去分n个尺寸不同的圆柱型的pie,其高为1.要注意n个pie分别不同,每个人分得的必须是同一个pie上的。问平均每个人最多可分得多少。
思路:二分,先找出上下界,下界为0,上界是n个pie中尺寸最大的那个,即每个人得到整个pie,而且是最大的那个。
   不断二分,若求出的人数大于f+1,说明现在分得的pie小了,更改min值,否则,更改max值;
 #include<stdio.h>
#include<math.h> const double PI = 3.1415926535898;
const double eps = 1e-; int main()
{
int test;
scanf("%d",&test);
while(test--)
{
int n,f;
double V[];
double min,max,mid;
min = 0.0;
max = 0.0; scanf("%d %d",&n,&f);
f += ;//加上主人共f+1人;
for(int i = ; i < n; i++)
{
scanf("%lf",&V[i]);
V[i] = V[i]*V[i];
if(max < V[i])
max = V[i];
} while(max - min > eps)
{
mid = (max+min)/;
int people = ;
for(int i = ; i < n; i++)
people += V[i]/mid;//每个人分得的pie必须来自于同一个pie,直接取整就行; if(people < f)
max = mid;
else min = mid;
}
double ans = PI*mid;
printf("%.4lf\n",ans);
}
return ;
}



Pie(二分)的更多相关文章

  1. HDU 1969 Pie(二分查找)

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

  2. HDU 1969 Pie(二分,注意精度)

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

  3. 【POJ 3122】 Pie (二分+贪心)

    id=3122">[POJ 3122] Pie 分f个派给n+1(n个朋友和自己)个人 要求每一个人分相同面积 但不能分到超过一个派 即最多把一整个派给某个人 问能平均分的最大面积 二 ...

  4. Pie(二分)

    http://poj.org/problem?id=3122 题意:将n个圆柱体的不同口味的pie分给m个人,要求每个人分得的pie必须体积相同,且来自于一块pie(即:只分得一种口味的pie),求最 ...

  5. Pie(二分POJ3122)

    Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12985   Accepted: 4490   Special Ju ...

  6. PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏

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

  7. 【hoj】2651 pie 二分查找

    二分查找是一个非常主要的算法,针对的是有序的数列,通过中间值的大小来推断接下来查找的是左半段还是右半段,直到中间值的大小等于要找到的数时或者中间值满足一定的条件就返回,所以当有些问题要求在一定范围内找 ...

  8. HDU1969:Pie(二分)

    Pie Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissio ...

  9. B - Pie (二分)

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

  10. UVaLive 3635 Pie (二分)

    题意:有f+1个人来分n个圆形派,每个人得到的必须是一个整块,并且是面积一样,问你面积是多少. 析:二分这个面积即可,小了就多余了,多了就不够分,很简单就能判断. 代码如下: #pragma comm ...

随机推荐

  1. linux 管道--转

    linux 管道 管道是Linux中很重要的一种通信方式,是把一个程序的输出直接连接到另一个程序的输入,常说的管道多是指无名管道,无名管道只能用于具有亲缘关系的进程之间,这是它与有名管道的最大区别. ...

  2. Vector/Arraylist与Linklist的区别

        SDK提供了有序集合接口java.util.List的几种实现,其中三种最为人们熟知的是Vector.ArrayList和    LinkedList.有关这些List类的性能差别是一个经常被 ...

  3. mac 下svn降级

    mac 手欠 homebrew 安装完成后  brew install  svn   svn版本更新至1.8.11 公司svn 不支持1.8  需要降级 搜索很多资料 写的比较麻烦 总结出来是先卸载再 ...

  4. IDL计算儒略日

    遥感数据还有一些文章中使用数据的时候,经常使用儒略日(Julian day),即计算该天是一年中的第几天.正好有时间,就用IDL写了段儿小代码,方便使用.   ;+   ; :Author: caoz ...

  5. C# ashx与html的联合使用

    本文将介绍ashx和html的联合使用方法,尽管目前流行mvc,但handler一般处理程序还是ASP.NET的基础知识,结合html页面,做出来的网页绝对比WebForm的简洁和效率高. 首先,概要 ...

  6. codevs 访问艺术馆

    /* codevs 1163 访问艺术馆 红果果的树形dp*/ #include<iostream> #include<cstdio> #include<cstring& ...

  7. 怎样使用svn开发项目

    那么首先什么是svn呢?官方有很好的解释,我说一下个人简单的理解,svn就是开源的版本控制软件, 那么什么是版本呢?简单的说版本就是标记,比如你买了一本书,同样的书名,但是版本不一定一样, 因为里面可 ...

  8. 自定义图文混排视图MyImageTextView

    http://blog.csdn.net/xujunfeng000/article/details/36399339?utm_source=tuicool&utm_medium=referra ...

  9. SQL Server死锁日志各字段含义

    使用跟踪标记 1204 --打开跟踪标记 DBCC TRACEON (1204,-1) --关闭跟踪标记 DBCC TRACEOFF (1204,-1) 处于死锁状态时,跟踪标记 1204 在等待的线 ...

  10. 内存泄漏在 WPF 和 Silverlight 提防

    瑞奇韭菜礼物 ︰ 内存泄漏在 WPF 和 Silverlight 提防 内存泄漏在 WPF 和 Silverlight 提防 WPF 和 Silverlight 允许您定义您的用户界面,用最少的代码将 ...