博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
4thweek.P_C poj3122 二分法
阅读量:4354 次
发布时间:2019-06-07

本文共 1409 字,大约阅读时间需要 4 分钟。

 

分配派问题题目大意

我要过生日了,准备了n个不同半径大小的圆形的pie,我有f 个朋友要来参加我的聚会,我要将pie公平分配,且给每人(包括我自己)分配一块尽量大的pie。(因为碎块看起来不上台面。)求分配每个人的pie的体积的最大值。(pie的厚度一定,等于1)

分析

运用二分法:将每个人能分配到的pie最大体积区间一直二分,直到不满足条件:while(left+0.0001<right)。   体积区间为[left,right]。

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 ≤ 10000: the number of pies and the number
of friends.
• One line with N integers ri with 1 ≤ ri ≤ 10000: 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 oating 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

代码及步骤分析:

1 #include
2 #include
3 #include
4 using namespace std; 5 const int m=10005; 6 double p[m]; 7 const double pi=acos(-1); 8 double max(double x,double y) 9 {10 if(x>=y)11 return x;12 else13 return y;14 }15 16 int main()17 {18 int t;19 scanf("%d",&t);20 while(t--)21 {22 int n,f,c,i;23 double sum=0, maxn=0;24 scanf("%d%d",&n,&f);25 f=f+1; // 人数需加上主人自己26 for(i=0;i

 

转载于:https://www.cnblogs.com/x512149882/p/4709366.html

你可能感兴趣的文章
火的合成心得。
查看>>
AngularJS_01之基础概述、设计原则及MVC设计模式
查看>>
Educational Codeforces Round 26 D. Round Subset
查看>>
【笔记】数论
查看>>
字典的常用操作
查看>>
C# 创建、部署和调用WebService的简单示例 (转)
查看>>
PHP面向对象(OOP)----访问限制符
查看>>
No qualifying bean of type [java.lang.String] found for dependency: expected
查看>>
人脸检测和识别主页
查看>>
PHP性能优化的五条技巧
查看>>
cocos2d-x注意点
查看>>
开发进度2
查看>>
滑动窗口
查看>>
nyoj-542 试制品 化学方程式 STL map 应用
查看>>
Validation failed for one or more entities while saving changes to SQL Server Database
查看>>
ACM水题
查看>>
Redis实例
查看>>
Android 布局
查看>>
windows下mongodb安装与使用整理
查看>>
EF6与mvc5系列(3):在MVC应用程序中使用EF进行排序,过滤和分页
查看>>