二分-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 ...
随机推荐
- mybatis 测试输出SQL语句到控制台配置
1: mybatis-config.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE ...
- 简单的试了试async和await处理异步的方式
今天无意中就来试了试,感觉这个新的方法还是非常行的通的,接下来我们上代码 这段代码想都不用想输出顺序肯定是//null null 233,当然出现这个问题还是因为它是同步,接下来我们就进行异步方式来处 ...
- Dalvik虚拟机和Art虚拟机
Dalvik虚拟机 DVM是Dalvik Virtual Machine的缩写,是Android4.4及以前使用的虚拟机,所有android程序都运行在android系统进程里,每个进程对应着一个Da ...
- 后端跨域的N种方法
简单来说,CORS是一种访问机制,英文全称是Cross-Origin Resource Sharing,即我们常说的跨域资源共享,通过在服务器端设置响应头,把发起跨域的原始域名添加到Access-Co ...
- Hadoop学习之路(8)Yarn资源调度系统详解
文章目录 1.Yarn介绍 2.Yarn架构 2.1 .ResourceManager 2.2 .ApplicationMaster 2.3 .NodeManager 2.4 .Container 2 ...
- 旷视向左、商汤向右,AI一哥之名将落谁家
编辑 | 于斌 出品 | 于见(mpyujian) AI风口历经多年洗礼之后,真正意义上的AI第一股终于要来了. 相比于聚焦在语音识别技术上的科大讯飞.立足互联网产业的百度.发力人形机器人领域的优必选 ...
- php 获取当前目录和当前文件夹
<?php /** * PHP获取路径或目录实现 */ //魔术变量,获取当前文件的绝对路径 echo "__FILE__: ========> ".__FILE__; ...
- 输出redis cluster集群所有节点指定的参数的配置
需要:实现类似redis-trib.rb call 命令的功能,输出redis cluster集群所有节点指定的参数的配置 redis-trib.rb的输出 [redis@lxd-vm3 ~]$ re ...
- 剑指offer-面试题30-包含min函数的栈-栈
/* 题目: 定义栈的数据结构,实现一个能够得到栈的最小元素的min函数. */ /* 思路: 错误思路:每次保存当前最小的元素,如果当前最小元素弹出,最小元素是谁? 正确思路:两个栈,一个栈保存数据 ...
- JAVA8对象属性的计算
Men men = new Men(); men.setName("UU"); men.setAge("56"); Men men1 = new Men(); ...