POJ 3122 Pie
来源:互联网 发布:卓越淘宝工具箱下载 编辑:程序博客网 时间:2024/06/07 02:31
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
思路:二分。WA了12次。
得到的启示是圆周率要这么写:
const double PI = acos(-1.0);
代码:
#include <cstdio>#include <iostream>#include <cstring>#include <vector>#include <map>#include <string>#include <cstring>#include <cmath>#include <algorithm>#define Pi 3.14159265358using namespace std;int n,f;double s[10000+10];int check(double m){ int sum=0; for(int i=0;i<n;i++) sum+=(int)(s[i]/m); if(sum>=f+1) return 1; return 0;}int main(void){ #ifdef LOCAL freopen("in.txt","rb",stdin); //freopen("out.txt","wb",stdout); #endif // LOCAL int t; cin >> t; for(int ii=1;ii<=t;ii++) { cin >> n >> f; double l=0,r=0,m; for(int i=0;i<n;i++) { double temp; cin >> temp; s[i]=temp*temp*Pi; r=max(r,s[i]); } while(fabs(r-l)>0.00001) { m=(l+r)/2; if(check(m)) l=m; else r=m; } printf("%.4lf\n",m); } return 0;}
- POJ-3122 Pie
- POJ 3122 Pie 二分
- POJ 3122 Pie 二分
- poj 3122 pie
- POJ 3122 Pie
- poj 3122 la3635 pie
- POJ 3122 Pie
- POJ-3122-Pie
- POJ 3122 Pie
- POJ 3122 Pie
- poj 3122 Pie
- poj 3122 pie
- POJ 3122 Pie
- POJ-3122 Pie
- POJ 3122--Pie
- POJ 3122Pie
- poj 3122 Pie (二分)
- POJ - 3122 Pie
- 一Java设计模式——需要遵守的六个原则
- iOS中如何优化Cell中图片的下载性能
- Apache HBase 2015年发展回顾与未来展望
- Tomcat6 一些调优设置内存和连接数
- 【scikit-learn】评估分类器性能的度量,像混淆矩阵、ROC、AUC等
- POJ 3122 Pie
- 数据说【DATASHUO】数据报告--谁偷了我的年终奖
- JavaScript isNaN() 函数
- RapidFloatingActionButton的使用心得
- C# 连接数据库(添加,修改,删除)
- java开发微信公众号企业付款开发
- 关于SwipeRefreshLayout+viewpager左右不能滑动
- Handler.removeCallbacksAndMessages(null)的作用
- java string为null时的字符串拼接