Pie
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10309   Accepted: 3651   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

Northwestern Europe 2006

AC代码:

#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
double pi=3.14159265359; //精度要足够大啊,要不wa死了
double v[10010];
int n,m;
double s,vm;
int judge(double mid){
int sum=0;
for(int i=1;i<=n;i++)
sum+=(int)(v[i]/mid);
if(sum>=m)
return 1;
return 0;
}
int main(){
int T; scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
s=0.0; m++;
for(int i=1;i<=n;i++){
double r; scanf("%lf",&r);
v[i]=pi*r*r;
s+=v[i];
}
vm=s/(m+0.0);
double left,right,mid;
left=0.0; right=vm;
while((right-left)>0.000001){
mid=(right+left)/2;
if(judge(mid))
left=mid;
else
right=mid;
}
printf("%.4lf\n",left);
}
return 0;
}

poj 3122的更多相关文章

  1. POJ 3122 & 3258 & 3273 #二分

    以下三道都是经典二分,道理都差不多,代码就贴在一起了. POJ 3122    POJ 3258    POJ 3273 POJ 3122: #include<iostream> #inc ...

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

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

  3. poj 3122 (二分查找)

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

  4. POJ 3122 Pie 二分枚举

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

  5. POJ - 3122 Pie(二分)

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

  6. POJ 3122 Pie【二分答案】

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

  7. POJ 3122 Pie

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

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

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

  9. poj 3122(二分查找)

    Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13564   Accepted: 4650   Special Ju ...

  10. Pie POJ 3122 二分搜索

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17324   Accepted: 5835   Special Judge ...

随机推荐

  1. CSUOJ 1637 Yet Satisfiability Again!

    1637: Yet Satisfiability Again! Time Limit: 5 Sec  Memory Limit: 128 MB Description Alice recently s ...

  2. qqwry - 纯真ip库的golang服务

    qqwry 纯真 IP 库的一个服务.通过http提供一个ip地址归属地查询支持 软件介绍 我们大家做网站的时候,都会需要将用户的IP地址转换为归属地址功能,而之前的作法大都是从硬盘的数据文件中读取, ...

  3. iOS 平台上常见的安装包有三种,deb、ipa 和 pxl

    前言:目前 iOS 平台上常见的安装包有三种,deb.ipa 和 pxl. 其中 deb 格式是 Debian 系统(包含 Debian 和 Ubuntu )专属安装包格式,配合 APT 软件管理系统 ...

  4. C语言之基本算法39—字符串经典操作

    //字符串概念! /* ================================================================== 题目:练习字符串的 1.输入输出      ...

  5. iOS Core Animation具体解释(四)AutoLayout中的动画

    原创blog.转载请注明出处 blog.csdn.net/hello_hwc 欢迎关注我的iOS SDK具体解释专栏 http://blog.csdn.net/column/details/huang ...

  6. C#中结构struct的使用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. amaze ui表格斑马纹效果

    amaze ui表格斑马纹效果 需要注意的是样式的写法,都是 am-table- ,很好记的 如果是条纹就是striped,如果是hover状态就是hover 用法很简单,点对应class,不同的cl ...

  8. vue中的插槽slot理解

    本篇文章参考赛冷思的个人博客 1.函数默认传参 在我们写js函数我们的可能会给他们一个默认的参数,写法是 function show(age,name){ var age = age || 20; v ...

  9. Kinect 开发 —— 语音识别(上)

    Kinect的麦克风阵列在Kinect设备的下方.这一阵列由4个独立的水平分布在Kinect下方的麦克风组成.虽然每一个麦克风都捕获相同的音频信号,但是组成阵列可以探测到声音的来源方向.使得能够用来识 ...

  10. 运动识别之HOJ3D和HMM

    http://cvrc.ece.utexas.edu/Publications/Xia_HAU3D12.pdf   View Invariant Human Action Recognition Us ...