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. <scrapy爬虫>scrapy命令行操作

    1.mysql数据库 2.mongoDB数据库 3.redis数据库 1.创建项目 scrapy startproject myproject cd myproject 2.创建爬虫 scrapy g ...

  2. 实现ViewPager的联动效果

    参考链接:android - Synchronizing two ViewPagers using OnPageChangeListener - Stack Overflow 其中有个非常完美的解决方 ...

  3. mysql数据库字段bigint使用

    Mysql里有个数据类型bigint 在java转换成实体对象时,处理不当容易出现以下异常: java.lang.ClassCastException: java.lang.Long cannot b ...

  4. Python全栈开发:configparser模块

    #!/usr/bin/env python # -*- coding;utf-8 -*- import configparser # 创建对象 conn = configparser.ConfigPa ...

  5. vue项目中,单页图片过多,使用懒加载

    最近做项目,一页图片很多,加载的时候效果很差. 通过学习借鉴其他大神的方法,使用了插件vue-lazyload,使用这个插件,界面更美观了,加载的效果好起来. 安装 npm i vue-lazyloa ...

  6. AutoIt自动化编程(3)【转】

    模拟鼠标点击(按钮等)控件 既然是模拟用户操作,自然就包括了模拟鼠标点击在内. 适用命令/函数:Click/MouseClick/ControlClick 其中Click/MouseClick用来模拟 ...

  7. AutoIt自动化编程(1)【转】

    1.运行程序 Run 命令或者函数用来运行外部可执行文件 AU3:Run ( "文件名" [, "工作目录" [, 标志]] ) EXAMPLE: AU3:Ru ...

  8. 介绍了Apache日志文件每条数据的请意义以及一些实用日志分析命令

    这篇文章主要介绍了apache日志文件每条数据的请意义,以及一些实用日志分析命令,需要的朋友可以参考下(http://wap.0834jl.com) 一.日志分析 如果apache的安装时采用默认的配 ...

  9. HashMap数据结构

    2.1 HashMap 2.1.1 HashMap介绍 先看看HashMap类头部的源码: public class HashMap<K,V> extends AbstractMap< ...

  10. DataV教你如何给可视化应用一键美颜

    视频观看地址:https://yunqivedio.alicdn.com/user-upload/T4WEb4C5Fc.mp4 如果你平时经常接触数据统计.数据展示和决策分析,相信你对DataV一定有 ...