Pie

Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 59   Accepted Submission(s) : 31

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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
#include <iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int t,n,f,i,num,x;
double pi=acos(-1.0); //不能写3.1415926
double l,r,mid;
double s[];
int cmp(double a,double b)
{
return a>b;
}
int main()
{
scanf("%d",&t);
for(;t>;t--)
{
scanf("%d%d",&n,&f);
f++;
double maxn=,sum=;
for(i=;i<=n;i++)
{
scanf("%d",&x);
s[i]=pi*x*x;
maxn=max(maxn,s[i]);
sum=sum+s[i];
}
l=maxn/f;
r=sum/f;
while(l+0.00001<r)
{
mid=(l+r)/;
num=;
for(i=;i<=n;i++) num+=(int)(s[i]/mid);
if (num>=f) l=mid;
if (num<f) r=mid;
}
printf("%.4lf\n",l);
//printf("%lf\n",acos(-1.0));;
}
return ;
}

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

  1. HDU 1969 Pie(二分查找)

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

  2. Hdu1969 Pie 2017-01-17 13:12 33人阅读 评论(0) 收藏

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

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

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

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

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

  5. Pie(二分)

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

  6. Pie(二分POJ3122)

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

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

  8. 【hoj】2651 pie 二分查找

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

  9. B - Pie (二分)

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

随机推荐

  1. js 弹出 隐藏层和cookie

    <script type="text/javascript"> function checkCookie(show_div, bg_div) { var smtstk ...

  2. 笨方法学python--提示别人

    1 上次学到使用raw_input(), 还可以如下使用: age = raw_input("age?") 2 命令名查看raw_input的说明 unit, pydoc raw_ ...

  3. jail brak 获取当前安装app列表

    ios 5 6 7 可以通过解析"/private/var/mobile/Library/Caches/com.app.mobile.installation.plist" 文件获 ...

  4. File文件操作类

    public class FileTest { //遍历出E:根目录下所有的文件夹,并输出文件夹名 static void testOne(){  //构建File对象,设置文件路径  File ro ...

  5. HDU - 5547 Sudoku(数独搜索)

    Description Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself ...

  6. java代理的深入浅出(三)-JavaAssist,ASM

    简介 类似字节码操作方法还有ASM.几种动态编程方法相比较,在性能上Javassist高于反射,但低于ASM,因为Javassist增加了一层抽象.在实现成本上Javassist和反射都很低,而ASM ...

  7. 【第三篇】学习 android 事件总线androidEventbus之发布事件,子线程中接收

    发送和接收消息的方式类似其他的发送和接收消息的事件总线一样,不同的点或者应该注意的地方: 1,比如在子线程构造方法里面进行实现总线的注册操作: 2,要想子线程中接收消息的功能执行,必须启动线程. 3, ...

  8. android:layout_weight属性的使用方法总结

    原创文章,转载请注明出处http://www.cnblogs.com/baipengzhan/p/6282826.html android:layout_weight属性可以和其他属性配合使用,产生多 ...

  9. Network view

    network view 组件用来在局域网之内去同步一个游戏物体的组件属性,只响应创建它的那个客户端事件

  10. 1.5后台修改添加TDK

    manager\includes\languages\english.php //注意 是后台的语言包define('BOX_CONFIGURATION_Lin_STORE', 'TDKcss_set ...