Pie
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 14536   Accepted: 4979   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
题目大意:国人很多事情都追求公平,分饼也是如此,现在这里有n个饼,每一个饼都可以看做一个圆柱体,高都是1,但是半径不同,
每一个人都可以分到某个饼的一部分,但是只能要一部分,而不能要好几块饼,最终结果必须保证每个人分到的饼的体积(面积)相等,
问你每个人能够获得的饼的最大面积是多少。
思路分析:首先数据量很大,如果用暴力枚举肯定会超时,很显然我们应该采用二分逼近的方法来确定答案,但是在实际操作的时候还是
出了一些问题,首先,二分精度不能够太高,1e-5就可以,精度太高会超时,其次,关于π,如果写做3.1415926会被精度卡掉,将pi
定义为acos(-1.0)就可以了。
代码:
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
#include <cmath>
#define LL long long
using namespace std;
const int maxn=10000+100;
const double pi=acos(-1.0);
double a[maxn];
int n,f;
double s(double r)
{
    return pi*r*r;
}
bool check(double x)
{
    int  t=0;
    for(int i=0;i<n;i++)
    {
        double p=s(a[i]);
        while(p>=x)
        {
            p-=x;
            t++;
            if(t>=f+1) return true;
        }
    }
    return false;
}
int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        double sum=0.0;
        scanf("%d%d",&n,&f);
        for(int i=0;i<n;i++)
        {
            scanf("%lf",&a[i]);
            sum+=s(a[i]);
        }
        sort(a,a+n);
        double l=0.0,r=sum/(f+1)*1.0;
        double ans=0;
        while(l+0.000001<=r)
        {
            double mid=(l+r)/2;
            if(check(mid)) ans=mid,l=mid;
            else r=mid;
        }
        printf("%.4lf\n",ans);
    }
    return 0;
}

poj3122 binary search 实数区间的更多相关文章

  1. uva 10304 - Optimal Binary Search Tree 区间dp

    题目链接 给n个数, 这n个数的值是从小到大的, 给出个n个数的出现次数. 然后用他们组成一个bst.访问每一个数的代价是这个点的深度*这个点访问的次数. 问你代价最小值是多少. 区间dp的时候, 如 ...

  2. Binary Search

    Binary Search                              [原文见:http://www.topcoder.com/tc?module=Static&d1=tuto ...

  3. Algo: Binary search

    二分查找的基本写法: #include <vector> #include <iostream> int binarySearch(std::vector<int> ...

  4. [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法

    二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...

  5. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  6. [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二

    Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...

  7. 【转】STL之二分查找 (Binary search in STL)

    Section I正确区分不同的查找算法count,find,binary_search,lower_bound,upper_bound,equal_range 本文是对Effective STL第4 ...

  8. STL之二分查找 (Binary search in STL)

    STL之二分查找 (Binary search in STL) Section I正确区分不同的查找算法count,find,binary_search,lower_bound,upper_bound ...

  9. 九章算法系列(#2 Binary Search)-课堂笔记

    前言 先说一些题外的东西吧.受到春跃大神的影响和启发,推荐了这个算法公开课给我,晚上睡觉前点开一看发现课还有两天要开始,本着要好好系统地学习一下算法,于是就爬起来拉上两个小伙伴组团报名了.今天听了第一 ...

随机推荐

  1. php魔术方法——构造函数和析构函数

    php有一类很神奇的方法,这些方法是保留方法,通常不会在外部被显式调用,他们使用双下划线(__)开头,他们被称为魔术方法(Magic Methods).php官方也不建议定义其他双下划线开头的方法. ...

  2. MySQL Left Join,Right Join

    魂屁,东西发这里了关于Left Join,Right Join的 在讲MySQL的Join语法前还是先回顾一下联结的语法,呵呵,其实连我自己都忘得差不多了,那就大家一起温习吧(如果内容有错误或有疑问, ...

  3. POJ1850 组合数学

    POJ1850 问题重述: 用26个小写字母进行编码,编码规则如下: 1)每个编码中前一个字母必须小于后一个字母 2)编码按照长度从小到大排列,相同长度按字典序进行排列 输入一个字母串,求解该编码对应 ...

  4. DEDE函数

    Html2text() 函数是去掉html标签代码. cn_substr(str,) 函数是截取字符串长度. 当然,他们也可以合并起来使用: [field:body function="cn ...

  5. DEDE首页调用{dede:field.content/}

    过滤DEDE后台自己添加的Class文件和HTML代码: {dede:sql sql='Select content from #@__arctype where id=1'} [field:cont ...

  6. Hadoop学习历程(二、配置)

    以下是进行单节点Hadoop配置的内容,多节点也类似 1. 进行Hadoop的安装 1.1 上文进行了Hadoop的编译,将编译结果目录 hadoop-2.2.0 拷贝为 /usr/hadoop 目录 ...

  7. swift字典集合-备

    Swift字典表示一种非常复杂的集合,允许按照某个键来访问元素.字典是由两部分集合构成的,一个是键(key)集合,一个是值(value)集合.键集合是不能有重复元素的,而值集合是可以重复的,键和值是成 ...

  8. 瞬态抑制二极管TVS的基本知识

    二极管是大家熟悉的元件,但瞬态抑制二极管就可能不太熟悉了.本文将介绍这种特殊二极管的用途. 工作原理等基本知识.各种电子设备中的各种半导体器件,一般都在直流低电压范围各作;如果在电源中串入一个瞬间上百 ...

  9. Activity切换效果(overridePendingTransition)

    在Android开发过程中,经常会碰到Activity之间的切换效果的问题,下面介绍一下如何实现左右滑动的切换效果,首先了解一下Activity切换的实现,从Android2.0开始在Activity ...

  10. 使用ngrok让微信公众平台通过80端口访问本机

    最近在做微信开发,感觉测试不怎么方便,在网上找了找一下帖子,发现了这个好工具哈,与大家一同分享一下... 原文:http://blog.csdn.net/liuxiyangyang/article/d ...