Pie
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 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

 #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(二分查找)的更多相关文章

  1. POJ 3122 二分

    大致题意: 就是公平地分披萨pie 我生日,买了n个pie,找来f个朋友,那么总人数共f+1人 每个pie都是高为1的圆柱体,输入这n个pie的每一个尺寸(半径),如果要公平地把pie分给每一个人(就 ...

  2. 【POJ】3122 Pie [二分查找]

    题目地址:http://poj.org/problem?id=3122 二分每块饼的体积.为了保证精度,可以先二分半径的平方r*r,最后再乘以PI.要注意一点,要分的人数要包括自己,及f+1. #in ...

  3. POJ 3273 Monthly Expense(二分查找+边界条件)

    POJ 3273 Monthly Expense 此题与POJ3258有点类似,一开始把判断条件写错了,wa了两次,二分查找可以有以下两种: ){ mid=(lb+ub)/; if(C(mid)< ...

  4. POJ 1064 Cable master(二分查找+精度)(神坑题)

    POJ 1064 Cable master 一开始把 int C(double x) 里面写成了  int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...

  5. POJ 3122 & 3258 & 3273 #二分

    以下三道都是经典二分,道理都差不多,代码就贴在一起了. POJ 3122    POJ 3258    POJ 3273 POJ 3122: #include<iostream> #inc ...

  6. poj 2452(RMQ+二分查找)

    题目链接: http://poj.org/problem?id=2452 题意:在区间[1,n]上找到满足 a[i]<a[k]<a[j] (i<=k<=j) 的最大子区间 (j ...

  7. 【POJ 3122】 Pie (二分+贪心)

    id=3122">[POJ 3122] Pie 分f个派给n+1(n个朋友和自己)个人 要求每一个人分相同面积 但不能分到超过一个派 即最多把一整个派给某个人 问能平均分的最大面积 二 ...

  8. POJ 3273 Monthly Expense二分查找[最小化最大值问题]

    POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...

  9. POJ——3061Subsequence(尺取法或二分查找)

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11224   Accepted: 4660 Desc ...

  10. POJ 2182 Lost Cows (树状数组 && 二分查找)

    题意:给出数n, 代表有多少头牛, 这些牛的编号为1~n, 再给出含有n-1个数的序列, 每个序列的数 ai 代表前面还有多少头比 ai 编号要小的牛, 叫你根据上述信息还原出原始的牛的编号序列 分析 ...

随机推荐

  1. 【BZOJ】1914: [Usaco2010 OPen]Triangle Counting 数三角形

    [题意]给定坐标系上n个点,求能构成的包含原点的三角形个数,n<=10^5. [算法]极角排序 [题解]补集思想,三角形个数为C(n,3)-不含原点三角形. 将所有点极角排序. 对于一个点和原点 ...

  2. 【51NOD】独木舟

    [算法]贪心 [题解]比较经典,用l,r两个定位指针分别从左右向中间推进. #include<cstdio> #include<algorithm> #include<c ...

  3. 【BZOJ】1385 [Baltic2000]Division expression

    [算法]欧几里德算法 [题解]紫书原题 #include<cstdio> #include<algorithm> using namespace std; ; int T,t, ...

  4. Mayor's posters(线段树+离散化+区间染色)

    题目链接:http://poj.org/problem?id=2528 题目: 题意:将n个区间进行染色(对于同一个区间,后一次染色会覆盖上一次的染色),问最后可见的颜色有多少种. 思路:由于区间长度 ...

  5. POj 2104 K-th Number (分桶法+线段树)

    题目链接 Description You are working for Macrohard company in data structures department. After failing ...

  6. bzoj 2121 DP

    首先如果我们能处理出来i,j段能不能消掉,这样就可以直接dp转移了,设w[i]为前i为最少剩下多少,那么w[i]=w[j-1] (flag[j][i]). 现在我们来求flag[i][j],首先我们可 ...

  7. js 的function为什么可以添加属性

    (1) function person(){ this.name = 'Tom'; } (2) function person(){} person.name = 'Tom'; (3) functio ...

  8. 64_a2

    arquillian-core-parent-1.1.11-6.fc26.noarch.rpm 10-Feb-2017 13:22 12918 arquillian-core-spi-1.1.11-6 ...

  9. MySQL多线程复制故障(slave_pending_jobs_size_max)

    MySQL多线程复制故障(slave_pending_jobs_size_max) http://www.xuchanggang.cn/archives/1079.html

  10. 转载: GIt远程操作详解

    Git远程操作详解   作者: 阮一峰 日期: 2014年6月12日 Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多优势,其中之一就是远程操作非常简便.本文详细介 ...