Pie

http://poj.org/problem?id=3122

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 24544   Accepted: 7573   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

Source

 
浮点数二分写法
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#define PI acos(-1.0)
using namespace std; int n,m;
double a[]; bool erfen(double r){
int sum=;
for(int i=;i<=n;i++){
sum+=int(a[i]/r);
}
if(sum>=m+) return true;
return false;
} int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d %d",&n,&m);
double L=,R=;
for(int i=;i<=n;i++){
scanf("%lf",&a[i]);
a[i]*=a[i];
if(a[i]>R) R=a[i];
}
while(R-L>0.00001){
double mid=(L+R)/;
if(erfen(mid)){
L=mid;
}
else{
R=mid;
}
}
printf("%.4f\n",PI*L);
}
system("pause");
}

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

  1. poj 1064 Cable master 判断一个解是否可行 浮点数二分

    poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...

  2. #AcWing系列课程Level-2笔记——4. 浮点数二分算法

    浮点数二分算法 编写浮点数二分,记住下面的思路,代码也就游刃有余了! 1.首先找到数组的中间值,mid=(left+right)>>1,区间[left, right]被划分成[left, ...

  3. Pie(二分)

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

  4. POJ - 3122 Pie(二分)

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

  5. HUD 1969:Pie(二分)

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

  6. HDU 1969 Pie【二分】

    [分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...

  7. 题解报告:hdu 1969 Pie(二分)

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

  8. POJ3122 Pie(二分)

    题目链接:http://poj.org/problem?id=3122 题意:一堆人分蛋糕,每人蛋糕大小一样,求最大能分多少,蛋糕必须是整块整块的,不能两块拼一起.然后注意输入F个人最后要分F+1份. ...

  9. hdoj 1969 Pie【二分】

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

随机推荐

  1. 1.环境搭建-mysql+tomcat+myeclipse安装并配置

    一.安装mysql数据库并配置 下载地址:https://pan.baidu.com/s/1OJ3ggda7Cthl4GCxWKbTng 密码:sd6b 1.打开安装程序

  2. HSSF NPOI 颜色

    using System; using System.IO; using System.Windows.Forms; using NPOI.HSSF.UserModel; using NPOI.SS. ...

  3. UMG设置组件自适应居中或靠边

    转自:http://aigo.iteye.com/blog/2297430 比如你的UI中有些组件需要居中显示,有些需要始终在右上角并且与上边框和右边框保持固定的距离等等,对于这种需要动态适应屏幕分辨 ...

  4. Hibernate 一对多/多对多

    一对多关联(多对一): 一对多关联映射: 在多的一端添加一个外键指向一的一端,它维护的关系是一指向多 多对一关联映射: 咋多的一端加入一个外键指向一的一端,它维护的关系是多指向一 在配置文件中添加: ...

  5. flask中的蓝图与红图

    内容: 1.flask中的蓝图 2.flask子域名实现 3.flask中的红图 1.flask中的蓝图 一个大型项目中视图比较多,如果仅仅是写在app.py中不方便管理,蓝图就可以做到分功能分目录结 ...

  6. python对象转字典

    1.基础实现 class TestDict: name = "wyb" age = " def __init__(self): self.gender = 'male' ...

  7. leetcode415

    public class Solution { public string AddStrings(string num1, string num2) { //判断num1和num2的长度,进行对齐 i ...

  8. mybatis - maven - eclipse 坑爹问题: No suitable driver found for http://maven.apache.org

    坑爹的问题,调查了1天 一直以为是驱动问题,根源却在url上:No suitable driver found for http://maven.apache.org 根源: 1.在jdbc.prop ...

  9. delphi IDE RAD 丢失的快捷键 Ctrl+Shift+F

    丢失的Ctrl+Shift+F delphi IDE RAD 丢失的快捷键 Ctrl+Shift+F Find inFiles 为什么呢?RAD Berlin安装了cnpack1.1.0.829后文件 ...

  10. 在mfc中picture控件中显示Mat图片<转>

    void ShowMatImgToWnd(CWnd* pWnd, cv::Mat img) { if(img.empty()) return; CRect drect; pWnd->GetCli ...