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 个朋友来参加我的生日party,m个蛋糕,我要把它平均分给每个人(包括我),并且每个人只能从一块蛋糕得到自己的那一份,并且分得的蛋糕大小要一样,形状可以不一样,每块蛋糕都是圆柱,高度一样。

 #include<cstdio>
#include<math.h>
double pi = acos(-1.0);
double sum,mid,le,ri,b[+],max0;
int n,f,r;
double fl(double x)
{
int su=;
for(int i = ; i < n ; i++)
{
su+=(int)(b[i]/x);
}
return su;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
sum=;
scanf("%d %d",&n,&f);
f++;
for(int i = ; i < n ; i++)
{
scanf("%d",&r);
b[i]=r*r*pi;
sum+=b[i];
}
sum=sum/f;
le=0.0;
ri=sum;
while(fabs(ri-le)>1e-)
{
mid=(le+ri)/;
if(fl(mid) >= f)
{
le=mid;
}
else
{
ri=mid;
}
}
printf("%.4f\n",le);
}
}
 
 
 
 
 

POJ 3122 pie (二分法)的更多相关文章

  1. POJ - 3122 Pie(二分)

    http://poj.org/problem?id=3122 题意 主人过生日,m个人来庆生,有n块派,m+1个人(还有主人自己)分,问每个人分到的最大体积的派是多大,PS每 个人所分的派必须是在同一 ...

  2. POJ 3122 Pie 二分枚举

    题目:http://poj.org/problem?id=3122 这个题就好多了,没有恶心的精度问题,所以1A了.. #include <stdio.h> #include <ma ...

  3. POJ 3122 Pie

    题目大意: 给出n个pie的直径,有f+1个人,如果给每人分的大小相同(形状可以不同),每个人可以分多少.要求是分出来的每一份必须出自同一个pie,也就是说当pie大小为3,2,1,只能分出两个大小为 ...

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

    Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22684   Accepted: 7121   Special Ju ...

  5. POJ 3122 Pie (贪心+二分)

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

  6. POJ 3122 Pie【二分答案】

    <题目链接> 题目大意: 将n个半径不一但是高度为1的蛋糕分给 F+1个人,每个人分得蛋糕的体积应当相同,并且需要注意的是,每个人分得的整块蛋糕都只能从一个蛋糕上切下来,而不是从几个蛋糕上 ...

  7. POJ 3122 Pie( 二分搜索 )

    链接:传送门 题意:一个小朋友开生日派对邀请了 F 个朋友,排队上有 N 个 底面半径为 ri ,高度为 1 的派,这 F 个朋友非常不友好,非得"平分"这些派,每个人都不想拿到若 ...

  8. POJ 3122 Pie 二分答案

    题意:给你n个派,每个派都是高为一的圆柱体,把它等分成f份,每份的最大体积是多少. 思路: 明显的二分答案题-- 注意π的取值- 3.14159265359 这样才能AC,,, //By Sirius ...

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

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

  10. poj 3122 (二分查找)

    链接:http://poj.org/problem?id=3122 Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1 ...

随机推荐

  1. java 丢失的异常

    采用finally从句中的,可能会丢失异常 package thinking; //: LostMessage.java // How an exception can be lost class V ...

  2. django_models表设计

    和很多现代的web框架一样,django依赖于强大的数据访问层,试图将python面向对象特性和关系型数据库联系起来. 可移植性:不同的数据库,可以使用同一段代码,不用关心后台是哪家的数据库. 在一个 ...

  3. LightOj 1076 - Get the Containers (折半枚举好题)

    题目链接: http://www.lightoj.com/volume_showproblem.php?problem=1076 题目描述: 给出n个数,要求分成m段,问这m段中最大的总和,最小是多少 ...

  4. Educational Codeforces Round 24 D

    Alice and Bob got very bored during a long car trip so they decided to play a game. From the window ...

  5. Lucky Array Codeforces - 121E && Bear and Bad Powers of 42 Codeforces - 679E

    http://codeforces.com/contest/121/problem/E 话说这题貌似暴力可A啊... 正解是想出来了,结果重构代码,调了不知道多久才A 错误记录: 1.线段树搞混num ...

  6. 从一个n位数中选出m位按顺序组成新数并使其最大 || Erasing and Winning UVA - 11491

    就是从n位数中取出n-d个数字按顺序排成一排组成一个新数使得其最大 算法: 从前往后确定每一位.找第i位时,要求后面留下d-i位的空间, 因此第i位应该从第i-1位原来位置+1到第d+i位寻找 用线段 ...

  7. JavaScript-获取当前元素的相关元素或节点--方法总结

    1.获取当前元素中的第一个子节点 document.getElementById("uu").firstChild 2.获取当前元素中的第一个子元素 document.getEle ...

  8. iOS开发隐藏tabBar的问题

    开发中遇到第一个页面需要显示tabBar,但是第二个页面不需要显示,当回到第一个页面的时候又需要显示的情况. 在第一个页面跳转到第二个页面的时候需要给第二个页面设置tabBar的隐藏 - (void) ...

  9. Python Unicode and str

    http://stackoverflow.com/questions/18034272/python-str-vs-unicode-types unicode is a character set. ...

  10. MySQLDump在使用之前一定要想到的事情 [转载]

    转载于:http://blog.itpub.net/29254281/viewspace-1392757/ MySQLDump经常用于迁移数据和备份. 下面创建实验数据,两个数据库和若干表create ...