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
解题思路:题意就是把n块饼分给f+1个人,要求每个人分得一块相同且面积最大的饼,不能由几小块凑成。因此,考虑从最大面积S的饼中进行二分取点,但这里跟二分查找有点区别的,相当于在一条绳子上取点,如果发现中点可以使分得馅饼的人数不小于f+1,那么左端点值应该赋值为mid,去找分得更大面积的馅饼(仔细想想是很容易明白的)不然误差会变大;同理如果中点使得分得馅饼的人数小于f+1,说明只能找较小的面积,那么右端点也赋值为mid,这样最后就能较精确的找到那个点mid。
AC代码:
 #include<bits/stdc++.h>
using namespace std;
const int maxn=;
const double pi=acos(-1.0);
const double eps=1e-7;
int t,n,f,cnt;double L,R,mid,r,maxsize,s[maxn];
int main(){
while(~scanf("%d",&t)){
while(t--){
scanf("%d%d",&n,&f);f+=;maxsize=0;
for(int i=;i<n;++i)scanf("%lf",&r),s[i]=pi*r*r,maxsize=max(maxsize,s[i]);//找出最大的馅饼面积
L=,R=maxsize;
while(R-L>eps){//因为只保留4位小数,所以精度控制在1e-7内即可(1e-8会超时)
mid=(R+L)/,cnt=;
for(int i=;i<n;++i)cnt+=floor(s[i]/mid);//取整
if(cnt>=f)L=mid;//如果发现可以分的人更多,那么就往右边找
else R=mid;//否则说明只能找小的尺寸,即往左边找
}
printf("%.4f\n",mid);
}
}
return ;
}

题解报告:hdu 1969 Pie(二分)的更多相关文章

  1. HDU 1969 Pie(二分查找)

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

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

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

  3. HDU 1969 Pie [二分]

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

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

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

  5. hdu 1969 Pie(二分查找)

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

  6. HDU 1969 Pie【二分】

    [分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...

  7. hdu 1969 pie 卡精度的二分

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

  8. HDU 1969 Pie(二分法)

    My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...

  9. HDU 1969 Pie(二分搜索)

    题目链接 Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pi ...

随机推荐

  1. Codeforces Round #422 (Div. 2) E. Liar 后缀数组+RMQ+DP

    E. Liar     The first semester ended. You know, after the end of the first semester the holidays beg ...

  2. 使用a标签下载文件,而不是直接打开,使用属性 download

    有的时候,下载的链接文件如果是普通文件类型,如txt,我们下载文件的时候,有的浏览器不会弹出下载框,.而是直接打开了该文件. 针对这种情况,我们只需要在a标签上加上download属性即可显示下载框. ...

  3. (linux)platform_driver_probe与platform_driver_register的区别

      [驱动注册]platform_driver_register()与platform_device_register()          设备与驱动的两种绑定方式:在设备注册时进行绑定及在驱动注册 ...

  4. vue2-editor富文本基础使用方法

    vue2-editor的入门使用准备工作: 使用 npm install vue2-editor --save 安装到项目中去: 使用 在需要的单文件内引入 import { VueEditor } ...

  5. 2款JS脚本判断手机浏览器跳转WAP手机网站

    随着移动设备的普及,企业的网络宣传已经不能局限在PC端,而需要同时在移动端有所建树.对于公司网站来说,以前都是做的PC端的,当然手机等移动端也可以访问,但是用户体验肯定不如完全适合的手机端来的方便.我 ...

  6. java在某个日期上添加n天的方法实现

    //得到添加n天后的时间字符串 public String getAddDate(Date date,int n){ //格式转换 SimpleDateFormat sdf = new SimpleD ...

  7. Luogu网校听课笔记(自用

    TG助学课——noilinux 8.2 深夜 Noi Linux的使用——darkflames的博客 #include<bits/stdc++.h> using namespace std ...

  8. 空间数据索引RTree完全解析及Java实现

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/MongChia1993/article/details/69941783 第一部分 空间数据的背景介 ...

  9. [TJOI2012]防御

    https://www.zybuluo.com/ysner/note/1332539 题面 戳我 解析 一道挺棒棒的线段树. 显然一次伤害到来时我们要先看看区间内哪些点的护甲没了. 这个可以通过维护区 ...

  10. laravel5.2数据库基本操作

    laravel5.2数据库基本操作 百牛信息技术bainiu.ltd整理发布于博客园 use Illuminate\Database\Eloquent\Model; use Illuminate\Da ...