Pie

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

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

f个人分n个圆柱形的馅饼,要求每人分到的馅饼体积相同,可以切割馅饼,但分给每个人的不能是零碎的,分给一个人的只能是从同一块上切下来的。最后输出每个人分到的体积。

可以根据体积二分来找到答案的体积。体积最小是0,(都没吃到),最大是馅饼总体积/总人数 (理想情况)。每次二分看该体积分的话可以分给多少人,如果可以分的人数大于等于f+1(因为自己也要吃),就把中间值赋给左边界。否则就赋给右边界。一直这样二分下去。直到r-l足够小

写得有点啰嗦。推荐https://blog.csdn.net/qq_36731677/article/details/54971485

 #include<bits/stdc++.h>
using namespace std;
double a[];
void init()
{
for(int i=;i<;i++)
{
a[i]=0.0;
}
}
int main()
{
int t;
while(~scanf("%d",&t))
{
while(t--)
{
init();
int n,f;double sum=;
scanf("%d %d",&n,&f);
for(int i=;i<n;i++)
{
scanf("%lf",&a[i]);
a[i]=acos(-1.0)*a[i]*a[i];
sum=sum+a[i]; }
//根据每个人分到的体积二分,最小是0,最大是馅饼总体积/总人数
double l=0.0,r=acos(-1.0)*sum,mid=(l+r)/2.0;
while(r-l>1e-)//精度不要设太高,容易t,也不要太低,适中
{
int temp=;
for(int i=;i<n;i++)
{
temp=temp+(int)(a[i]/mid);
}
if(temp>=f+)
{
l=mid;
mid=(l+r)/2.0;
}
if(temp<f+)
{
r=mid;
mid=(l+r)/2.0;
} }
printf("%.4lf\n",mid);
} }
return ;
}

hdu1969Pie(根据体积二分,分馅饼)的更多相关文章

  1. 分馅饼 Pie

    Pie 链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/C 题目: Problem Description ...

  2. POJ3122Pie(二分)

    http://poj.org/problem?id=3122 题意 :这个题最主要的就是审题要仔细,翻译不要漏句子.题目讲的是我要过生日,要给好友分馅饼(还有自己也想要一块),怕引起不公,所以每个人大 ...

  3. PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏

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

  4. hdu 5954 -- Do not pour out(积分+二分)

    题目链接 Problem Description You have got a cylindrical cup. Its bottom diameter is 2 units and its heig ...

  5. [SinGuLaRiTy] 分治题目复习

    [SInGuLaRiTy-1025] Copyrights (c) SinGuLaRiTy 2017. All Rights Reserved. [POJ 1905] 棍的膨胀 (Expanding ...

  6. ACM pie

    我的生日快到了,传统上我正在做馅饼.不只是一个馅饼,不,我有N个,各种口味和各种尺寸. 数量为F我的朋友会来到我的聚会,每个人都得到一个馅饼. 这应该是一块馅饼,而不是几个小块,因为看起来很乱.这一块 ...

  7. HDU1969 Pie(二分搜索)

    题目大意是要办生日Party,有n个馅饼,有f个朋友.接下来是n个馅饼的半径.然后是分馅饼了, 注意咯自己也要,大家都要一样大,形状没什么要求,但都要是一整块的那种,也就是说不能从两个饼中 各割一小块 ...

  8. IC 小常识

    IC产品的命名规则: 大部分IC产品型号的开头字母,也就是通常所说的前缀都是为生产厂家的前两个或前三个字母,比如:MAXIM公司的以MAX为前缀,AD公司的以AD为前缀,ATMEL公司的以AT为前缀, ...

  9. DO-214 SMA、SMB、SMC封装

    DO-214 is a standard that specifies a group of semiconductor packages for surface mounted diodes. Th ...

随机推荐

  1. iOS开发中方法延迟执行的几种方式

    概述 项目开发中经常会用到方法的延时调用,下面列举常用的几种实现方式: 1.performSelector 2.NSTimer 3.NSThread线程的sleep 4.GCD 1.performSe ...

  2. hpp.h与.h的区别

    hpp,其实质就是将.cpp的实现代码混入.h头文件当中,定义与实现都包含在同一文件,则该类的调用者只需要include该hpp文件即可,无需再将cpp加入到project中进行编译.而实现代码将直接 ...

  3. phpstudy 出现You don't have permission to access / on this server.

    You don't have permission to access / on this server. 去掉vhost文件中的Options FollowSymLinks ExecCGI 第一次发 ...

  4. [转载] iOS应用程序的生命周期

    iOS应用程序的生命周期 2015-06-23 iOS大全 (点击上方蓝字,快速关注我们) iOS应用程序一般都是由自己编写的代码和系统框架(system frameworks)组成,系统框架提供一些 ...

  5. 系统优化怎么做-Tomcat优化

    大家好,这里是「聊聊系统优化 」,并在下列地址同步更新 博客园:http://www.cnblogs.com/changsong/ 知乎专栏:https://zhuanlan.zhihu.com/yo ...

  6. about route

    route add default dev  my_iface1 route del default route add default gw 192.168.120.1 route add -net ...

  7. Illegal modifier for parameter userMapper; only final is permitted

    报错的原因是 package com.chen.service.impl; import java.io.IOException; import java.io.InputStream; import ...

  8. Mysql基于Linux上的安装

    MySQL 在Linux/Unix安装 所有平台的 MySQL 下载地址为: MySQL 下载 . 挑选需要的 MySQL Community Server 版本及对应的平台. 注意:安装过程需要通过 ...

  9. Linux 学习第三天

    一.常用命令 1.diff A.diff -q 源文件 目标文件  (快速比较文件是否相同) 2.ifconfig.nmcli (查看配置信息) 命令输入注意: Windows 查看网卡配置信息输入命 ...

  10. 转:Java中的cas

    引自:https://blog.csdn.net/mmoren/article/details/79185862 本篇的思路是先阐明无锁执行者CAS的核心算法原理然后分析Java执行CAS的实践者Un ...