UVALive - 3635 Pie
来源:互联网 发布:网络层的协议内容 编辑:程序博客网 时间:2024/04/30 04:23
Problem C - Pie
Time limit: 1 second
My birthday is coming up and traditionally I'm serving pie. Not justone pie, no, I have a number N of them, of various tastes andof various sizes. F of my friends are coming to my party andeach 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 onewhole pie though.
My friends are very annoying and if one of them gets a bigger piecethan the others, they start complaining. Therefore all of them shouldget equally sized (but not necessarily equally shaped) pieces, even ifthis leads to some pie getting spoiled (which is better than spoilingthe party). Of course, I want a piece of pie for myself too, and thatpiece should also be of the same size.
What is the largest possible piece size all of us can get? All thepies 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. Thenfor each test case:
- One line with two integers N and F with 1 ≤N, F ≤ 10000: the number of pies and the number offriends.
- 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 volumeV such that me and my friends can all get a pie piece of sizeV. The answer should be given as a floating point numberwith 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
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const double pi=acos(-1.0);
const int maxn=10000+5;
int n,f;
double a[maxn];
bool ok(double area)
{
int sum=0;
for(int i=0;i<n;i++)
sum+=floor(a[i]/area);
return sum>=f+1;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&f);
double maxa=-1;
for(int i=0;i<n;i++)
{
int r;
scanf("%d",&r);
a[i]=pi*r*r;
maxa=max(maxa,a[i]);
}
double L=0,R=maxa;
while(R-L>1e-5)
{
double M=(L+R)/2;
if(ok(M)) L=M;
else R=M;
}
printf("%.5lf\n",L);
}
return 0;
}
- UVALive - 3635 Pie
- UVALIVE 3635 Pie 二分
- UVALive - 3635 Pie
- UVALive - 3635 Pie
- UVALive - 3635 Pie 二分
- UVALive 3635 Pie
- UVALive 3635-Pie-二分
- UVALive 3635 Pie 【二分】
- UVALive 3635 Pie 二分查找
- UVALive 3635 Pie (二分答案)
- UVALive 3635 Pie (二分)
- UVALive - 3635 - Pie(二分)
- pie(UVALive
- uvalive 3635 - Pie(二分搜索)
- UVALive 3635 Pie 切糕大师 二分
- uvalive 3635 - Pie(二分搜索)
- 例题1.13 派 Pie UVALive
- LA 3635 Pie
- 计算机专业毕业论文的选题的重要性和选题原则
- Linux 内存管理 -- 高端内存的映射方式
- 5.预处理和筛选法
- [django每日学习14.11.7]关于django runserver创建的网站其他计算机无法访问
- SDL2源代码分析5:更新纹理(SDL_UpdateTexture())
- UVALive - 3635 Pie
- linux Oracle常用数据库操作命令
- NSLOG的描述
- 对于上个文章进销存的流程图补充
- /proc/diskstats
- [转]C++性能优化技术导论
- Codeforces Round #276 (Div. 2)
- C/C++ sort函数的用法
- 按登录IP记录Linux所有用户操作日志