二分-C - Pie
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 2Sample Output
25.1327
3.1416
50.2655
#include<iostream>
#include<cmath>
using namespace std; const double pi=acos(-1.0);
const int maxn = ;
double a[maxn];
int n,k;
int solve(double x){
int sum=;
for(int i=;i<n;i++)
sum += (int)(a[i]*a[i]*pi/x);
if(sum >= k+) return ;
else return ;
} int main()
{
int t;
scanf("%d", &t);
while(t--){
scanf("%d %d", &n, &k);
double right = , left = , mid;
for(int i=; i<n; i++){
scanf("%lf", a+i);
if(a[i]*a[i]*pi > right) right = a[i]*a[i]*pi;
}
while(right - left > 1e-){
mid = (right + left)/;
if(solve(mid)) left = mid;
else right = mid;
}
printf("%.4lf\n",mid);
}
}
∏ = acos(-1.0)
二分-C - Pie的更多相关文章
- HDU 1969 精度二分
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- Pie(二分)
ime Limit: 1000MS Memory Limit: 65536K Total Submissions: 8930 Accepted: 3235 Special Judge De ...
- 【二分答案】【POJ3122】【Northwestern Europe 2006】Pie
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10629 Accepted: 3744 Special Ju ...
- UVALive 3635 Pie 切糕大师 二分
题意:为每个小伙伴切糕,要求每个小盆友(包括你自己)分得的pie一样大,但是每个人只能分得一份pie,不能拿两份凑一起的. 做法:二分查找切糕的大小,然后看看分出来的个数有没有大于小盆友们的个数,它又 ...
- HDU 1969 Pie(二分查找)
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- POJ - 3122 Pie(二分)
http://poj.org/problem?id=3122 题意 主人过生日,m个人来庆生,有n块派,m+1个人(还有主人自己)分,问每个人分到的最大体积的派是多大,PS每 个人所分的派必须是在同一 ...
- HUD 1969:Pie(二分)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- Pie(浮点数二分)
Pie http://poj.org/problem?id=3122 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2454 ...
- HDU 1969 Pie(二分,注意精度)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
随机推荐
- 多柱汉诺塔问题“通解”——c++
多柱汉诺塔问题 绪言 有位同学看到了我的初赛模拟卷上有一道关于汉诺塔的数学题.大概就是要求4柱20盘的最小移动次数. 他的数学很不错,找到了应该怎样推. 如果要把n个盘子移到另一个柱子上,步骤如下: ...
- node中 package.json 文件说明
1.概述 每个项目的根目录下面,一般都有一个package.json文件,定义了这个项目所需要的各种模块,以及项目的配置信息(比如名称.版本.许可证等元数据).npm install命令根据这个配置文 ...
- JaveScript遍历数组的方法
JaveScript遍历数组的方法 第一种:for循环 遍历出数组的每个值 let arr = [1, 2, 3, 4, 5, 6, 7, 8]; for (let i = 0; i < arr ...
- C语言再学习part1-宏观认识C语言
天下莫柔弱于水,而攻坚强者莫之能胜,以其无以易之也.弱之胜强,柔之胜刚,天下莫不知行,莫能行. —老子 我近来每天都在坚持读书,所以我一直沉浸于古人的智慧中无法自拔.所以如果我这篇博文被你有幸看到,那 ...
- mysql 行级锁问题
线上碰到存储过程死锁问题了,开始以为非主键查询 for update 会导致表锁,后来经过测试 innodb下for update索引生效的情况下 根据索引字段查询是行级锁,会将整个结果集进行上锁,直 ...
- python3.6安装PyUserInput
python3.6安装PyUserInput https://www.cnblogs.com/yoyoketang/p/8043814.html
- Python集合详解
集合介绍: 集合(set)是一个无序的不重复元素序列.可以使用大括号 { } 或者 set() 函数创建集合,注意:创建一个空集合必须用 set() 而不是 { },因为 { } 是用来创建一个空字典 ...
- WebGL_0002:palycanvas 配置文件路径
playcanvas 配置文件路径https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/wmSPTNhb/config.jsonsence 地址 ...
- 在Docker中部署Confluence和jira-software
-------谢谢您的参考,如有疑问,欢迎交流 version: centos==7.2 jdk==1.8 confluence==6.15.4 jira-software==8.2.1 docker ...
- 【Thread】java线程之对象锁、类锁、线程安全
说明: 1.个人技术也不咋滴.也没在项目中写过线程,以下全是根据自己的理解写的.所以,仅供参考及希望指出不同的观点. 2.其实想把代码的github贴出来,但还是推荐在初学的您多亲自写一下,就没贴出来 ...