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. wpf 定时器应用,在界面动态刷新时间

    DispatcherTimer = new DispatcherTimer(); Timer.Tick += Timer_Tick; Timer.Interval = TimeSpan.FromSec ...

  2. node中没有全局作用域,只有模块作用域(文件作用域)

    node中没有全局作用域,只有模块作用域(文件作用域)

  3. MongDB4.0-入门学习之运算符

    MongDB 4.0 入门学习之运算符 基本语法:db.collection.find({<key>:{$symbol:<value>}}) 条件查询匹配运算符 符号 描述 范 ...

  4. F. Cowmpany Cowmpensation dp+拉格朗日插值

    题意:一个数,每个节点取值是1-d,父亲比儿子节点值要大,求方案数 题解:\(dp[u][x]=\prod_{v}\sum_{i=1}^xdp[v][i]\),v是u的子节点,先预处理出前3000项, ...

  5. 3、变量+运算符+Scanner

    1.变量 1>开辟内存空间 int num ; 2>赋值 num = 10; 3>使用 num 1*long 类型的特殊 long num = 12L 2*float类型特殊 flo ...

  6. React报错:Laravel React-Router browserHistory 刷新子页面报错404

    举例:myblog.com/ 刷新没问题 myblog.com/add 刷新404 browserHistory报404,hashHistory却正常 原因是少路由.web.php添加路由 Route ...

  7. 我喜欢Mouding

    我Smily喜欢Mouding

  8. 郝斌–SQL Server2005学习笔记

    数据库(Database)狭义上是指存储数据的仓库,广义上包含对数据进行存储和管理的软件(DBMS)和数据本身.数据库由表.关系和操作组成. 一.数据库简介 1.为什么需要数据库 数据库简化了对数据的 ...

  9. iOS之CGPath的应用(二)

    1.矩形路径 CG_EXTERN CGPathRef CGPathCreateWithRect(CGRect rect, const CGAffineTransform * __nullable tr ...

  10. JDK源码阅读--AbstractStringBuilder

    abstract class AbstractStringBuilder implements Appendable, CharSequence /** * The value is used for ...