poj 3122(二分查找)
| Time Limit: 1000MS | Memory Limit: 65536K | |||
| Total Submissions: 13564 | Accepted: 4650 | 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
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
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<iomanip>
#include<queue>
#include<stack>
using namespace std;
#define N 10000
#define PI 3.1415926535897932384626
double r[N],v,d,c,ma;
int main(){
//freopen("in.txt","r",stdin);
std::ios::sync_with_stdio(false);
cin>>c;
while(c--){
int n,f;
cin>>n>>f;
f++;
ma=0.0;
for(int i=;i<n;i++){
cin>>r[i];
r[i]*=r[i];
if(ma<r[i]) ma=r[i];
}
double up,low,mid;
low=0.0;up=ma;
while(up-low>1e-){
mid=(up+low)/;
int num=;
for(int i=;i<n;i++)
num+=(int)(r[i]/mid);
if(num>=f)
low=mid;
else
up=mid;
}
cout<<fixed<<setprecision()<<mid*PI<<endl;
}
return ;
}
poj 3122(二分查找)的更多相关文章
- POJ 3122 二分
大致题意: 就是公平地分披萨pie 我生日,买了n个pie,找来f个朋友,那么总人数共f+1人 每个pie都是高为1的圆柱体,输入这n个pie的每一个尺寸(半径),如果要公平地把pie分给每一个人(就 ...
- 【POJ】3122 Pie [二分查找]
题目地址:http://poj.org/problem?id=3122 二分每块饼的体积.为了保证精度,可以先二分半径的平方r*r,最后再乘以PI.要注意一点,要分的人数要包括自己,及f+1. #in ...
- POJ 3273 Monthly Expense(二分查找+边界条件)
POJ 3273 Monthly Expense 此题与POJ3258有点类似,一开始把判断条件写错了,wa了两次,二分查找可以有以下两种: ){ mid=(lb+ub)/; if(C(mid)< ...
- POJ 1064 Cable master(二分查找+精度)(神坑题)
POJ 1064 Cable master 一开始把 int C(double x) 里面写成了 int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...
- POJ 3122 & 3258 & 3273 #二分
以下三道都是经典二分,道理都差不多,代码就贴在一起了. POJ 3122 POJ 3258 POJ 3273 POJ 3122: #include<iostream> #inc ...
- poj 2452(RMQ+二分查找)
题目链接: http://poj.org/problem?id=2452 题意:在区间[1,n]上找到满足 a[i]<a[k]<a[j] (i<=k<=j) 的最大子区间 (j ...
- 【POJ 3122】 Pie (二分+贪心)
id=3122">[POJ 3122] Pie 分f个派给n+1(n个朋友和自己)个人 要求每一个人分相同面积 但不能分到超过一个派 即最多把一整个派给某个人 问能平均分的最大面积 二 ...
- POJ 3273 Monthly Expense二分查找[最小化最大值问题]
POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...
- POJ——3061Subsequence(尺取法或二分查找)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11224 Accepted: 4660 Desc ...
- POJ 2182 Lost Cows (树状数组 && 二分查找)
题意:给出数n, 代表有多少头牛, 这些牛的编号为1~n, 再给出含有n-1个数的序列, 每个序列的数 ai 代表前面还有多少头比 ai 编号要小的牛, 叫你根据上述信息还原出原始的牛的编号序列 分析 ...
随机推荐
- 并查集入门--畅通工程(HDU1232)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232 畅通工程 Time Limit: 4000/2000 MS (Java/Others) M ...
- patch需要数据格式前端算法,patch算法基础,两个对象对比取差异属性
在我们的前端开发过程中,表单是最常见不过的了,一般我们创建表单的时候习惯使用post方法来提交数据,编辑表单时候喜欢put,但是当表单的数据非常多的时候,编辑起来很麻烦,首先需要获取初始化数据,然后把 ...
- Msfvenom学习总结-MSF反弹webshell
1. –p (- -payload-options) 添加载荷payload. 载荷这个东西比较多,这个软件就是根据对应的载荷payload生成对应平台下的后门,所以只有选对payload,再填 ...
- AlertDialog.Builder 显示为白色 蓝色字
AlertDialog.Builder dialog = new AlertDialog.Builder( getActivity(),AlertDialog.THEME_HOLO_LIGHT);
- 一种面向云服务的UCON多义务访问控制方法及系统
)设置每一云服务的义务项:建立每一云服务所包含的义务图:2)根据用户所请求的云服务查找该云服务的所有强制义务图和可选义务图,并提取该用户对该云服务的历史完成情况:3)对每一强制义务图,监控其每一义务项 ...
- java 和 JVM
C++和Java的区别 指针:java中不存在指针的概念,编程者无法直接通过指针来直接访问内存,有利于维护java程序的安全 多重继承:C++支持多重继承,java不支持多重继承,但是允许一个类继承多 ...
- 神奇JavaScript框架---Top5
前言 个人观点,供您参考 观点源自作者的使用经验和日常研究 排名基于框架的受欢迎度, 语法结构, 易用性等特性 希望大家能够基于此视频找到最适合自己的框架 下面介绍的都是严格的前端框架和库 前言 To ...
- javascript方法--apply()
今天琢磨了一下apply,以前对这个方法觉得比较懵,今天一琢磨确实觉得挺好玩的. 一开始把MDN的apply文档看了一遍,感觉不是很理解,而且有一些东西也是知道但是比较模糊,所以还是一步一步来,不懂查 ...
- leetcode 136 137 Single Number
题目描述(面试常考题) 借助了异或的思想 class Solution { public: int singleNumber(vector<int>& nums) { ; ; i ...
- django中使用第三方包实现定时任务
# 转载请留言联系 在做主页静态化的时候,需要定时生成主页HTML,以保持数据的最新. 定时任务可以用第三方包django-crontab来实现. 附上官方文档:https://pypi.org/pr ...