hdu1969(二分)
来源:互联网 发布:市场调研数据分析 编辑:程序博客网 时间:2024/05/18 05:28
Pie
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4547 Accepted Submission(s): 1837
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.
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
题目大意:N块饼,F个朋友,还有自己;每个人分得一块相同分量的饼,不能由几小块凑成,求能分成的最大体积/面积。
分析:精度要求高,pi要用反余弦pi=acos(-1.0);
#include <cstdio>#include <cmath>#include <iostream>#include <algorithm>using namespace std;double pi = acos(-1.0);int N,F,t;double v[11111];int main(){ int T; int N,F; int i; int r; double left,right,mid; double v[10011]; scanf("%d",&T); while(T--) { scanf("%d%d",&N,&F); F++;//加上自己 right = 0; for(i=0; i<N; i++) { scanf("%d",&r); v[i] = pi * r * r; right = max(right, v[i]);//找出面积最大的饼,为二分上界 } left=0; mid=(left + right) / 2; while(right - left >= 0.0000001)//精度要求 { t=0; for(i=0; i<N; i++) t += (int)(v[i]/mid); if(t >= F) left = mid; else right = mid; mid = (left + right) / 2; } printf("%0.4lf\n",mid); } return 0;}
0 0
- hdu1969(二分)
- hdu1969 Pie (二分)
- HDU1969:Pie(二分 + 贪心)
- hdu1969 Pie 二分
- hdu1969(pie二分)
- hdu1969之二分查找
- HDU1969---Pie 二分
- HDU1969:Pie(二分)
- 二分查找 hdu1969 pie
- hdu1969 Pie 二分
- HDU1969 PIE 二分查找
- hdu1969 Pie(二分答案)
- HDU1969 Pie(二分搜索)
- hdu1969 pie【二分】
- HDU1969:Pie(二分)
- Hdu1969-Pie-【二分】
- poj 3122&&hdu1969 Pie(二分)
- 【hdu1969】Pie——二分
- 华为机试之if语句条件判断
- 【数据结构】图的遍历
- c语言字符串
- CSS中的containing block
- 【01背包问题】【AsiaRegionalAnshanOnline2014】HDU5000Clone
- hdu1969(二分)
- Android dagger2使用
- 又到了入学季,谈谈软件研发的团队建设
- 最短路径—Dijkstra算法和Floyd算法
- java 的 多态机制
- 练练手--求串联电阻的阻值
- hdu1018(斯特灵公式)
- 欢迎使用CSDN-markdown编辑器
- [leetcode-115]Distinct Subsequences(java)