Pie(浮点数二分)
Pie
http://poj.org/problem?id=3122
| Time Limit: 1000MS | Memory Limit: 65536K | |||
| Total Submissions: 24544 | Accepted: 7573 | 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 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
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
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#define PI acos(-1.0)
using namespace std; int n,m;
double a[]; bool erfen(double r){
int sum=;
for(int i=;i<=n;i++){
sum+=int(a[i]/r);
}
if(sum>=m+) return true;
return false;
} int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d %d",&n,&m);
double L=,R=;
for(int i=;i<=n;i++){
scanf("%lf",&a[i]);
a[i]*=a[i];
if(a[i]>R) R=a[i];
}
while(R-L>0.00001){
double mid=(L+R)/;
if(erfen(mid)){
L=mid;
}
else{
R=mid;
}
}
printf("%.4f\n",PI*L);
}
system("pause");
}
Pie(浮点数二分)的更多相关文章
- poj 1064 Cable master 判断一个解是否可行 浮点数二分
poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...
- #AcWing系列课程Level-2笔记——4. 浮点数二分算法
浮点数二分算法 编写浮点数二分,记住下面的思路,代码也就游刃有余了! 1.首先找到数组的中间值,mid=(left+right)>>1,区间[left, right]被划分成[left, ...
- Pie(二分)
ime Limit: 1000MS Memory Limit: 65536K Total Submissions: 8930 Accepted: 3235 Special Judge De ...
- POJ - 3122 Pie(二分)
http://poj.org/problem?id=3122 题意 主人过生日,m个人来庆生,有n块派,m+1个人(还有主人自己)分,问每个人分到的最大体积的派是多大,PS每 个人所分的派必须是在同一 ...
- HUD 1969:Pie(二分)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- HDU 1969 Pie【二分】
[分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...
- 题解报告:hdu 1969 Pie(二分)
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- POJ3122 Pie(二分)
题目链接:http://poj.org/problem?id=3122 题意:一堆人分蛋糕,每人蛋糕大小一样,求最大能分多少,蛋糕必须是整块整块的,不能两块拼一起.然后注意输入F个人最后要分F+1份. ...
- hdoj 1969 Pie【二分】
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
随机推荐
- tomcat 性能优化(内存优化 线程优化)
转自:http://blog.sina.com.cn/s/blog_4b5bc01101014s81.html tomcat 性能优化 linux修改TOMCAT_HOME/bin/catalina. ...
- 样式学习--参照Oracle写法
#------------------------------------------------------------------------------- # Do not change the ...
- 最近比赛中遇到的几道dp题
1.2015 icpc 长春-H-Partial Tree(据说是完全背包,但我觉得不像) 一.题意 给定$n$个点,每一个点$i$的权值为关于度数$d_i$的函数$f(d_i),$让你构建一棵树,使 ...
- 【洛谷】P1641 [SCOI2010]生成字符串(思维+组合+逆元)
题目 传送门:QWQ 分析 不想画图. https://www.luogu.org/problemnew/solution/P1641 好神仙的题啊. 代码 // luogu-judger-enabl ...
- Web API 源码剖析之默认配置(HttpConfiguration)
Web API 源码剖析之默认配置(HttpConfiguration) 我们在上一节讲述了全局配置和初始化.本节我们将就全局配置的Configuration只读属性进行展开,她是一个类型为HttpC ...
- linux 下各个4K区块文件大小测试速度对比 机械硬盘性能 64K性价比收益最高
机械硬盘,每个区块取三次数最小值为准,带2G RAM缓存卡 4K3.4 MB/秒 8K7.3 MB/秒 16K9.5 MB/秒 32K16.7 MB/秒 64K44.2 MB/秒 128K67.1 M ...
- Ubuntu16安装QQ
安装教程: 一:安装依赖库 在终端输入sudo apt-get install libgtk2.0-0:i386 另外,如果是64位系统还要安装ia32-libs 这里我们选择安装lib32ncurs ...
- Arrays.binarySearch 数组二分查找
public static void main(String[] args) throws Exception { /** * binarySearch(Object[], Object key) a ...
- C关键字typedef及argc,argv,env参数含义
C关键字typedef--为C中各种数据类型定义别名. 在此插一点C知识 int main(int argc,const char *argv[],const char *envp[])主函数的红色部 ...
- leetcode134
class Solution { public: inline int get_next(int idx, int size) { ? : idx+; } int aux(int idx, vecto ...