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

题目倒是不难,比较容易想,但是这个精确度确实是有点恶心...WA了6,7次。首先需要注意什么地方要用double,什么地方要转int,其次也学会了在小数范围内用二分,之前一直WA竟然是二分判断的时候小数点后0不够多,,,加了一个0后立马AC...醉惹,那个排序貌似并没有什么用...原来32ms,排序后16ms...

 #include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <cstdio>
#include <queue>
#pragma warning ( disable : 4996 ) using namespace std; int Max( int x, int y ) { return x>y?x:y; }
int Min( int x, int y ) { return x>y?y:x; } const int inf = 0x3f3f3f3f;
const int vspot = 1e4 + ;
const int espot = 1e5 + ;
const double PI = 3.1415926535897932; int N, F;
double rad[vspot]; bool cmp( int a, int b )
{
return a>b;
} int main()
{
int all;
scanf( "%d",&all );
while (all--)
{
scanf( "%d %d", &N, &F ); F++;
int x, fin;
double sum = ;
for( int i = ; i < N; i++ )
{ scanf( "%d", &x ); rad[i] = x*x; sum += rad[i]; } double rhs = sum/F, lhs = 0.0;
double mid;
//sort( rad, rad+N, cmp ); while ( rhs - lhs > 0.0000001 )
{
fin = ;
mid = (rhs+lhs)/;
for ( int i = ; i < N; i++ )
{
//if ( rad[i] < mid )
// break;
fin += (int)(rad[i]/mid);
}
if ( fin >= F )
lhs = mid;
else
rhs = mid;
} printf( "%.4lf\n", PI*mid ); }
return ;
}

POJ 3122 Pie (贪心+二分)的更多相关文章

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

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

  2. POJ - 3122 Pie(二分)

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

  3. POJ 3122 Pie【二分答案】

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

  4. POJ 3122 & 3258 & 3273 #二分

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

  5. POJ 3122 Pie 二分枚举

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

  6. POJ 3122 Pie 二分答案

    题意:给你n个派,每个派都是高为一的圆柱体,把它等分成f份,每份的最大体积是多少. 思路: 明显的二分答案题-- 注意π的取值- 3.14159265359 这样才能AC,,, //By Sirius ...

  7. POJ 3122 Pie

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

  8. POJ 3122 Pie( 二分搜索 )

    链接:传送门 题意:一个小朋友开生日派对邀请了 F 个朋友,排队上有 N 个 底面半径为 ri ,高度为 1 的派,这 F 个朋友非常不友好,非得"平分"这些派,每个人都不想拿到若 ...

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

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

随机推荐

  1. 重温robotframework--day1

    RF支持中文编码设置 1.python2.6  [PythonDir]\Lib\site-packages\robot\utils下的encoding.py文件中,在文件上点击右键,选择Edit wi ...

  2. JAVA中日期 yyyy-MM-dd HH:mm:ss和yyyy-MM-dd hh:mm:ss的区别

    HH是24小时制,hh是12小时制 区别就是:大写的H是二十四小时制的小时数(0-23),小写的h是十二小时制的小时数(am/pm 1-12) //24小时制 SimpleDateFormat sdf ...

  3. spring:bean的细节之三种创建Bean对象的方式

    <!--创建Bean的三种方式--><!--第一种方式,使用默认构造函数创建 在spring的配置文件中使用bean标签,配以id和class属性之后,且没有属性和标签时. 采用的就 ...

  4. html--双飞翼布局

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. antidependence and data hazard

    See below example. ADDD  F6, F0, F8 SUBD   F8, F10, F14 Some article would say that “ There’s an ant ...

  6. js '' ""的嵌套使用

    1.我需要拼接一个字符串,但是其中 单引号内包含了双引号,双引号内又包含了单引号变量 这时我们想到了可以用到HTML特殊转义字符 2.如下拼接 return '<input type=" ...

  7. 面向对象_访问修饰符_构造与析构函数_this指针

    1:面向对象 以codeblocks举例,在一个工程里面: File-->new -->Class可以建一个类,可以设置类的参数,是否有set get方法,有无构造函数等设置,.h文件主要 ...

  8. Struts2OGNL

    OGNL: 什么是OGNL  Object Graph Navigation Language 开源项目,取代页面中Java脚本,简化数据访问 和EL同属于表达式语言,但功能更为强大  OGNL在St ...

  9. C++和C#之间的数据类型对应关系

    最近接触WINAPI比较多,一直要楂数据类型间的对应关系,所姒就转载一下~ # Windows Data Type .NET Data Type # BOOL, BOOLEAN Boolean or ...

  10. Ubuntu18上安装Go和GoLand

    第一步骤:安装Go 方式一: 使用 sudo apt-get install golang命令安装 ubuntu软件库里当前golang版本为1.10,(golang最新版为1.11),可满足要求. ...