HDOJ 1969 Pie
来源:互联网 发布:sql里values什么意思 编辑:程序博客网 时间:2024/04/29 22:43
Pie
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
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.
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.
---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
33 34 3 31 24510 51 4 2 3 4 5 6 5 4 2
Sample Output
25.13273.141650.2655
对体积进行二分,根据半径把每个圆柱体体积算出来,存到数组里,找到体积的最大值,注意f要加加;
代码:
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;double a[10010];//#define PI 3.1415926#define PI acos(-1.0)int n,f;bool judge(double mid){int sum=0;for(int i=1;i<=n;i++){sum=sum+(int)(a[i]/mid);if(sum>=f) return true;}return sum>=f;}int main(){int t;scanf("%d",&t);while(t--){double v=0;scanf("%d%d",&n,&f);f++;for(int i=1;i<=n;i++){scanf("%lf",&a[i]);a[i]=a[i]*a[i]*PI;v+=a[i];}sort(a+1,a+n+1);double l=0,r=v;int size=100;while(size--){double mid=(l+r)/2.0;if(judge(mid)){l=mid;}else{r=mid;}}printf("%.4lf\n",l);}return 0;}</pre></div>
0 0
- hdoj 1969 Pie 【二分】
- hdoj 1969 Pie
- hdoj 1969 pie【二分法】
- hdoj 1969 Pie
- HDOJ 1969 Pie (二分)
- HDOJ 1969 Pie
- HDOJ 1969 Pie
- HDOJ-1969 Pie
- hdoj 1969 Pie 【二分】
- HDOJ 1969 Pie(二分查找)
- HDOJ 1969 Pie(二分)
- hdoj 1969 (poj 3122&&acm)Pie
- (二分)Pie--HDOJ
- Num 23 : HDOJ : 2199 Can you solve this equation? + HDOJ : 1969 Pie [ 二分法 ]
- 1969 Pie
- HDU 1969 Pie
- hdu 1969 Pie
- HDU 1969 - Pie
- network干货
- 随机生成三个数,计算其中素数的和
- 使用Bootstrap FileInput遇到的坑
- Android数据存储(一)----SharedPreferences详解
- iOS--textfield的拓展
- HDOJ 1969 Pie
- 详解JSP九大内置对象
- 生成or判别?
- Hessian+Maven Demo 一个简单的实例(有问题,可以提问,经常在线,源码会粘上连接,可下载)
- 切割回文(区间dp)
- Task schedule<hdoj4907>
- 经常利用文档与搜索引擎其实未必是好事
- Pie
- java基础——String和StringBuffe、StringBuilder