(二分)Pie--HDOJ
来源:互联网 发布:淘宝篮球鞋店推荐 编辑:程序博客网 时间:2024/05/17 03:25
Pie
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1044 Accepted Submission(s): 388
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
NWERC2006
Recommend
wangye
总结:
题意,N张馅饼,高度忽略,分给F+1个人,并且每个人的面积都相同,求分到的最大的面积,注意,每个人得到的面积必须是一块,不能是几块拼到一块的。
用二分法查找合适的面积,在fun函数里面,用每一块馅饼的面积去分block大小的馅饼,记录能分多少块,统计所有馅饼能分的块数,与人数进行比较,分的块数多于人数,则说明block小了,应st=mid,如果分的块数小于人数,则说明block太大啦,应ed =mid。。
#include<iostream>#include<string.h>#include<algorithm>#include<math.h>using namespace std;double num[10005],sum=0;int n,f;int fun(double block){ int res=0; for(int i=0; i<n; ++i) res += (int )(num[i]/block); return res >= f;}int main(){ int ncase; cin >> ncase; while(ncase--) { scanf("%d %d",&n,&f); double mx=0; for(int i=0; i<n; ++i) { double t; scanf("%lf",&t); num[i] = t*t*acos(-1.0); mx = max(mx,num[i]); } f++; double st=0,ed=mx,mid; while((ed-st) > 0.000001) { mid = (st + ed) / 2.0; if(fun(mid)) st = mid; else ed = mid; } printf("%.4lf\n",st); } return 0;}
- hdoj 1969 Pie 【二分】
- HDOJ 1969 Pie (二分)
- hdoj 1969 Pie 【二分】
- (二分)Pie--HDOJ
- HDOJ 1969 Pie(二分查找)
- HDOJ 1969 Pie(二分)
- Pie(二分)
- 【二分】Pie
- Pie (二分)
- Pie 【二分】
- Pie 二分
- Pie[二分]
- hdoj 1969 Pie
- hdoj 1969 pie【二分法】
- hdoj 1969 Pie
- HDOJ 1969 Pie
- HDOJ 1969 Pie
- HDOJ-1969 Pie
- CentOS6.5安装MongoDB详解
- UML类图关系示例
- 优化服务器网络访问速度:解决CURL慢的问题-关闭IPV6支持。
- 【有源汇上下界最小流】BZOJ2502[清理雪道]题解
- RN开发模型
- (二分)Pie--HDOJ
- 那些年我们在Python掉进的坑——清除不想要的字符
- Poj 2139 Six Degrees of Cowvin Bacon (floyd最短路)
- 推荐学习方法——“三遍读书法”
- 分辨出字符串中的重复数字并计算求和
- sscanf函数的用法
- hdu 6038 Function
- JSP中的EL表达式详细介绍
- 使用Express创建node.js项目