POJ 3122 Pie
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26920 Accepted: 8150 Special Judge 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
Northwestern Europe 2006
二分,看代码能懂!
#include<iostream>
#include<cstdio>
#include<cmath>
#define PI 3.14159265358979
#define LL long long
#define eps 0.0000001
using namespace std;
double ans[10010];
int n,m,t;
bool judge(double a)
{
int sum=0;
for(int i=1;i<=n;++i)
{
sum+=(int)(ans[i]*1.0/a);
}
if(sum>=m+1) return 1;
else return 0;
}
int main()
{
//freopen("input.txt","r",stdin);
cin>>t;
while(t--)
{
cin>>n>>m;double max_=-10000000;
for(int i=1;i<=n;++i)
{
int a;
cin>>a;
ans[i]=PI*a*a;
max_=max(ans[i],max_);
}
double L=0,H=max_;double mid;
while(fabs(H-L)>eps)
{
mid=(H+L)/2;
if(judge(mid)) L=mid;
else H=mid;
}
printf("%.4fn",L);
}
}
- 如何在Redhat中安装R的包及搭建R的私有源
- 什么是sparklyr
- 如何利用Dnsmasq构建小型集群的本地DNS服务器
- Cloudera Labs中的Phoenix
- 如何在CDH中使用Phoenix
- Java 8 时间 API 快速入门
- 如何在CDH中使用HPLSQL实现存储过程
- 如何掌握所有的编程语言
- 如何使用Sentry管理Hive外部表(补充)
- WebLogic XMLDecoder反序列化漏洞(CVE-2017-10271)漏洞复现&修复方案
- 如何在CDSW中使用R绘制直方图
- CTF学习交流群 第一期入群题writeup大放送
- 如何使用Hue创建Spark1和Spark2的Oozie工作流
- 【译】深入研究 Laravel 的依赖注入容器
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Android UI中TextView的使用方法
- Android 中通过ViewDragHelper实现ListView的Item的侧拉划出效果
- 浅谈Android中使用异步线程更新UI视图的几种方法
- Android gradle打包并自动上传的方法
- Android 后台发送邮件到指定邮箱
- Android中socketpair双向通信详解
- Android滚动条广告实现代码示例
- Android使用Recyclerview实现图片水平自动循环滚动效果
- Android selector的实例详解
- Android底部弹窗的实现示例代码
- Android编程实现自定义渐变颜色效果详解
- ES11屡试不爽的新特性,你用上了几个?
- Android设计模式之策略模式详解
- Android实现类似iOS风格的对话框实例代码
- Android 给图片加上水印的示例代码(支持logo+文字)