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. kibana 和ES安装配置常见问题解决

    1.下载相同版本的kibana和ES: es5.6.5下载地址:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5 ...

  2. beans有无状态

    Spring Bean Scopes https://www.tutorialspoint.com/spring/spring_bean_scopes.htm When defining a < ...

  3. Qt 模拟鼠标点击(QApplication::sendEvent(ui->pushbutton, &event0);)

    QPoint pos(0,0);QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt ...

  4. postman app支持浏览器上的cookie

    1.  安装postman app 注意要安装postman application(一个应用软件),而不是chrome 插件,打开下面的这个开关 2. chrom浏览器 给chrom浏览器安装pos ...

  5. 由SOAP说开去 - - 谈谈WebServices、RMI、RPC、SOA、REST、XML、JSON

    引子: 关于SOAP其实我一直模模糊糊不太理解,这种模模糊糊的感觉表述起来是这样: 在使用web服务时(功能接口),本来我就可以通过安卓中固有的http类(使用http协议),来发送http请求,并且 ...

  6. 迁移学习与fine-tuning有什么区别

    假设你要处理一个新数据集,让你做图片分类,这个数据集是关于Flowers的,问题是,数据集中flower的类别很少,数据集中的数据也不多,你发现从零开始训练CNN的效果很差,很容易过拟合,怎么办呢,于 ...

  7. springboot 使用model重定向到html模板,对数据进行展示

    1:使用springboot, ,html使用thymeleaf,nekohtml模板 在build.gradle中添加依赖 buildscript { repositories { mavenCen ...

  8. PAT 1065 A+B and C[大数运算][溢出]

    1065 A+B and C (64bit)(20 分) Given three integers A, B and C in [−2​63​​,2​63​​], you are supposed t ...

  9. C++中的常量定义

    本篇笔记总结自一次代码检视. 一般来说,使用C语言编程时我们都习惯在代码当中使用C当中的宏定义来定义一个数值常量: #define MY_CONST 7 在C++开发项目时,也会经常存在沿袭C当中常量 ...

  10. zoj3822

    这题说得是给了一个n*m的棋盘,每天在这个棋盘中放置一个棋子,不能放在之前已经摆放过得地方,求最后使得每行每列都有至少一个棋子的期望天数是多少,这样我们考虑怎么放,放哪里,显然数据大而且不知道状态怎么 ...