Pie

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12394    Accepted Submission(s): 4371

Problem 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
 
Source
 
二分每块pie的大小即可,主要是精度问题,由于精确到1e-4所以while(r-l>0.0001)即可,但是里面对于r的操作不写精度+-得话就能A,如果写必须注意精度了开到1e-7才A   (⊙﹏⊙)b
#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1.0)
double a[10005],F,N;
bool can(double s)
{
  int sum=0,i;
  for(i=1;i<=N;++i) sum+=floor(a[i]/s);
  return sum>=F;
}
int main()
{
    int i,j,k,t;
    cin>>t;
    while(t--){
        cin>>N>>F;
        F++;
        for(i=1;i<=N;++i) {
                cin>>a[i];
                a[i]=a[i]*a[i]*PI;
        }
        double l=0,r=10000*10000*PI,mid;
        while(r-l>0.00001){
            mid=r-(r-l)/2;
            if(can(mid)){
                l=mid;
            }
            else{
                r=mid-0.0000001;
            }
        }
        printf("%.4f\n",l);
    }
    return 0;
}

 

HDU 1969 精度二分的更多相关文章

  1. HDU 1969 Pie(二分,注意精度)

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

  2. HDU 1969 Pie(二分查找)

    Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...

  3. (step4.1.2)hdu 1969(Pie——二分查找)

    题目大意:n块馅饼分给m+1个人,每个人的馅饼必须是整块的,不能拼接,求最大的. 解题思路: 1)用总饼的体积除以总人数,得到每个人最大可以得到的V.但是每个人手中不能有两片或多片拼成的一块饼. 代码 ...

  4. HDU 1969 Pie [二分]

    1.题意:一项分圆饼的任务,一堆圆饼共有N个,半径不同,厚度一样,要分给F+1个人.要求每个人分的一样多,圆饼允许切但是不允许拼接,也就是每个人拿到的最多是一个完整饼,或者一个被切掉一部分的饼,要求你 ...

  5. hdu 1969 pie 卡精度的二分

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

  6. hdu 1969 Pie(二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others)    Me ...

  7. hdu 1969(二分)

    题意:给了你n个蛋糕,然后分给m+1个人,问每个人所能得到的最大体积的蛋糕,每个人的蛋糕必须是属于同一块蛋糕的! 分析:浮点型二分,二分最后的结果即可,这里要注意圆周率的精度问题! #include& ...

  8. 题解报告:hdu 1969 Pie(二分)

    Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...

  9. Pie(hdu 1969 二分查找)

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

随机推荐

  1. 徐州网络赛J-Maze Designer【最小生成树】【LCA】

    After the long vacation, the maze designer master has to do his job. A tour company gives him a map ...

  2. Oracle安装部署之 timesten install on redhat6.5

    一.安装前检查 [root@localhost ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.5 (San ...

  3. has to be escaped using backslash to be included in string value\n

    [root@d myssh]# cat ESdel_bulk_file1544528090.log{"error":{"root_cause":[{" ...

  4. HDU1530 Maximum Clique dp

    正解:dp 解题报告: 这儿是传送门 又是个神仙题趴QAQ 这题就直接说解法辣?主要是思想比较难,真要说有什么不懂的知识点嘛也没有,所以也就没什么好另外先提一下的知识点QAQ 首先取反,就变成了求最大 ...

  5. android:layout_gravity 和 android:gravity

    android:layout_gravity和 android:gravity的区别,android:gravity是对元素本身说的,元素本身的文本显示在什么地方靠着 换个属性设置,不过不设置默认是在 ...

  6. RDD, DataFrame or Dataset

    总结: 1.RDD是一个Java对象的集合.RDD的优点是更面向对象,代码更容易理解.但在需要在集群中传输数据时需要为每个对象保留数据及结构信息,这会导致数据的冗余,同时这会导致大量的GC. 2.Da ...

  7. Kd-tree的学习

    一.普通kd-tree 1.在选择划分维度的时候,不能简单的每一个维度轮流划分.还有一种更合适的是利用数据的方差来划分,哪个维度的方差大,就选择哪一个维度划分.理由解释如下: 最简单的方法就是轮着来, ...

  8. SCons构建工具使用

    scons是一个Python写的自动化构建工具,和GNU make相比优点明显:    1. 移植性:python能运行的地方,就能运行scons    2. 扩展性:理论上scons只是提供了pyt ...

  9. Jquery 简明介绍

    http://www.cnblogs.com/luotianshuai/p/5196997.html http://www.cnblogs.com/liujianzuo888/articles/568 ...

  10. SpringData_JpaRepository接口

    该接口提供了JPA的相关功能 List<T> findAll(); //查找所有实体 List<T> findAll(Sort sort); //排序.查找所有实体 List& ...