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 ≤ 10000: the number of pies and the number of friends.
  • One line with N integers ri with 1 ≤ ri ≤ 10000: 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+1个人来分N个圆形派,每个人得到的必须是一整块派,而不是几块拼在一起,且面积要相同。求出每个人最多能得到多大面积的派(不必是圆形) 分析:解决在“最小值最大”的常用方法是二分答案。本题虽然不是这个问题,但仍然可以采用二分答案方法,把问题转化为“是否可以让每人得到一块面积为x的派”。这样的转化相当于多了一个条件,然后求解目标变成了“看看这些条件是否相互矛盾”。
  会有怎样的矛盾呢?只有一种矛盾,x太大,满足不了所有的F+1个人。这样,我们只需要算一算一共可以切成多少份面积为x的派,然后看看这个数目够不够F+1即可。因为派是不可以拼起来的,所以一个半径为r的派只能切出[PI*r2/x]个派(其他部分就浪费了) ,把所有圆形派能切出的份数加起来即可。 代码如下:
 #include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std; const double PI = acos(-1.0);
const int maxn = + ; int n, f;
double A[maxn]; bool ok(double area) {
int sum = ;
for(int i = ; i < n; i++) sum += floor(A[i] / area);
return sum >= f+;
} int main() {
int T;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &f);
double maxa = -;
for(int i = ; i < n; i++) {
int r;
scanf("%d", &r);
A[i] = PI*r*r; maxa = max(maxa, A[i]);
}
double L = , R = maxa;
while(R-L > 1e-) {
double M = (L+R)/;
if(ok(M)) L = M; else R = M;
}
printf("%.5lf\n", L);
}
return ;
}
 

UVA 12097 LA 3635 Pie(二分法)的更多相关文章

  1. LA 3635 Pie 派 NWERC 2006

    有 f + 1 个人来分 n 个圆形派,每个人得到的必须是一整块派,而不是几块拼在一起,并且面积要相同.求每个人最多能得到多大面积的派(不必是圆形). 这题很好做,使用二分法就OK. 首先在读取所有派 ...

  2. LA 3635 Pie

    题意:给出n个圆,分给n+1个人,求每个人最多能够得到多大面积的圆 二分每个人得到的圆的面积 #include<iostream> #include<cstdio> #incl ...

  3. Uva 派 (Pie,NWERC 2006,LA 3635)

    依然是一道二分查找 #include<iostream> #include<cstdio> #include<cmath> using namespace std; ...

  4. UVALive 3635 Pie(二分法)

    简单的二分法应用,循环1000次精度就满足要求了. #include<iostream> #include<cstdio> #include<cstdlib> #i ...

  5. uva 12097 - Pie

    简单题,二分就行: #include<cstdio> #include<cmath> #define pi acos(-1.0) #define eps 0.000001 #d ...

  6. UVa Live 3635 - Pie 贪心,较小的可能不用 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  7. UVA 12097 Pie(二分答案)

    题目链接: 这道题虽然不是一道典型的二分答案题,但同样也可以用二分答案来做. 来二分面积为$area$的派,然后看看条件是否矛盾. 与其矛盾的便是$f+1$个人是否每个人都会有. 一个半径为$r$的派 ...

  8. Java实现派(Pie, NWERC 2006, LA 3635)

    题目 有F+1个人来分N个圆形派,每个人得到的必须是一整块派,而不是几块拼在一起,且面积要相同.求每个人最多能得到多大面积的派(不必是圆形). 输入的第一行为数据组数T.每组数据的第一行为两个整数N和 ...

  9. hdu 1969 Pie (二分法)

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

随机推荐

  1. android获取屏幕分辨率

    DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); dm. ...

  2. POJ 3295 Tautology (构造题)

    字母:K, A, N, C, E 表示逻辑运算 字母:p, q, r, s, t 表示逻辑变量 0 或 1 给一个字符串代表逻辑表达式,如果是永真式输出tautology 否则输出not 枚举每个逻辑 ...

  3. 给新手的 10 个有用 Linux 命令行技巧

    我记得我第一次使用 Linux 的时候,我还习惯于 Windows 的图形界面,我真的很讨厌 Linux 终端.那时候我觉得命令难以记忆,不能正确使用它们.随着时间推移,我意识到了 Linux 终端的 ...

  4. PC-大概最全的黑客工具表了

    纯真IP数据库查询程序 ­ remote administrator ­ (rar解密)ZiperelloV2.0 汉化版.zip ­ (代理跳板)SkSockServer1.09.zip ­ [ar ...

  5. 第一步 配置D2RQ环境

    ​第一步 配置D2RQ环境 Getting Started 2013年10月15日 15:16:55 老套路,还是先配置环境,没查到什么中文资料,写在这里,供大家参考.有需要交流的可以加QQ: 1q7 ...

  6. Javascript 高阶函数等

    高阶函数 函数可以接受另一个函数作为参数 称为 高阶函数. map : arr.map(pow); 数组.map(函数); reduce :arr.reduce(function(){ }); 数组. ...

  7. 图像处理界的标准图像Lena背后的故事

    今天晚上实验室的哥们问到我:“蒋志强,你知道咱们数字图像处理界标准图像Lena吗?” “当然知道啊,不就是那个512×512的美丽姐姐的标准图像么?”我不以为然的回答: “那幅图像事实上不是原始图像? ...

  8. [ATL/WTL]_[0基础]_[CBitmap复制图片-截取图片-平铺图片]

    场景: 1.当你须要截取图片部分区域作为某个控件的背景. 2.须要平铺图片到一个大区域让他自己主动放大时. 3.或者须要合并图片时. 代码: CDC sdc; CDC ddc; sdc.CreateC ...

  9. CentOS 配置httpd使局域网能够正常訪问

    [转载请注明出处: 钱国正的专栏http://blog.csdn.net/qianguozheng/article/details/37611859] 问题: 在CentOS上安装apache,配置好 ...

  10. CameraTest

    from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage #device = MonkeyRunner.wa ...