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. tomcat下获取当前路径的url中含有空格解决方法

    参考博文(http://www.360doc.com/content/11/1009/17/4602013_154657565.shtml) web项目发布到Tomcat之后,如果tomcat是安装在 ...

  2. Dot Product

    These are vectors: They can be multiplied using the "Dot Product" (also see Cross Product) ...

  3. [ An Ac a Day ^_^ ] hdu 1003 dp

    超时还有可能是数组开小了…… #include<stdio.h> #include<iostream> #include<algorithm> #include&l ...

  4. 判断手机电脑微信 js

    if ((navigator.userAgent.match(/(MicroMessenger)/i))) { //微信浏览器 //location.href=""; } else ...

  5. POJ 2488 A Knight's Journey(深搜+回溯)

    A Knight's Journey Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) ...

  6. CSS居中方法

    css居中方法非常多,根据工作的实际情况采用恰当方法,可取到事半功倍的效果. 就常见的一些居中方法整理如下: 代码如下: <div class="con"> <d ...

  7. mysql5.7.16安装

    系统:centOS6.5 mysql: 5.7.16 wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16-linux-glib ...

  8. Java创建对象的4种方式?

     [Java创建对象的4种方式?] 1)通过new语句实例化一个对象 2)通过反射机制创建对象 3)通过clone()方法创建一个对象  (复制) 4)通过反序列化方式创建对象

  9. codeforce Gym 101102A Coins (01背包变形)

    01背包变形,注意dp过程的时候就需要取膜,否则会出错. 代码如下: #include<iostream> #include<cstdio> #include<cstri ...

  10. 关于LCD的分屏与切屏 Tearing effect

    详细文档(带图片):http://download.csdn.net/detail/xuehui869/5268852 1.LCM之Fmark功能 http://blog.csdn.net/zhand ...