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 ;
}

最新文章

  1. for循环每次取出一个字符(不是字节)
  2. XVII Open Cup named after E.V. Pankratiev. GP of SPb
  3. linux开机自动连接无线网络
  4. Guid.NewGuid()
  5. React开发项目例子
  6. Codeforces Gym 100338C C - Important Roads tarjan
  7. Android——显示当前运行所有服务,判断服务是否运行
  8. jquerymobile知识点:动态Grid的绑定以及刷新
  9. 2.PHP 教程_PHP 安装
  10. 解决ubuntu server mysql load data infile 导入本地文件ERROR 1148 (42000)错误。
  11. IM 融云 之 开发基础概念
  12. 1724: [Usaco2006 Nov]Fence Repair 切割木板
  13. div排版+文档流+定位秘诀
  14. QQ浏览器等window.innerHeight首次读取的高度不正确的解决办法
  15. MySQL多数据源笔记2-Spring多数据源一主多从读写分离(手写)
  16. AngularJS 全局scope与指令 scope通信
  17. 一个.net的程序员如何转到java的?
  18. 交叉编译ffmpeg(hi3520d)
  19. json null
  20. sql语句基础(一)

热门文章

  1. python2.7 安装Django
  2. Module、__init__.py 文件解析
  3. HDU 1250 Hat&#39;s Fibonacci(大数相加)
  4. SecureCRT连接主机时(串口/网络),无法从键盘输入
  5. SQLite 如何取出特定部分数据
  6. LogViewer超大文本浏览工具
  7. 坑爹的jquery ui datepicker
  8. Vue路由钩子 afterEach beforeEach区别
  9. css 浮动说明
  10. 《MySQL必知必会》--使用cmd登陆数据库