poj 3122(二分查找)

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

Northwestern Europe 2006

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cstdlib>
 6 #include<cmath>
 7 #include<vector>
 8 #include<iomanip>
 9 #include<queue>
10 #include<stack>
11 using namespace std;
12 #define N 10000
13 #define PI 3.1415926535897932384626
14 double r[N],v,d,c,ma;
15 int main(){
16     //freopen("in.txt","r",stdin);
17     std::ios::sync_with_stdio(false);
18     cin>>c;
19     while(c--){
20         int n,f;
21         cin>>n>>f;
22         f++;
23         ma=0.0;
24         for(int i=0;i<n;i++){
25             cin>>r[i];
26             r[i]*=r[i];
27             if(ma<r[i]) ma=r[i];
28         }
29         double up,low,mid;
30         low=0.0;up=ma;
31         while(up-low>1e-6){
32             mid=(up+low)/2;
33             int num=0;
34             for(int i=0;i<n;i++)
35                 num+=(int)(r[i]/mid);
36             if(num>=f)
37                 low=mid;
38             else
39                 up=mid;
40         }
41         cout<<fixed<<setprecision(4)<<mid*PI<<endl;
42     }
43     return 0;
44 }
时间: 2024-08-09 19:51:59

poj 3122(二分查找)的相关文章

poj 3122 (二分查找)

链接:poj 3122 题意:我生日派对时,准备了n个圆柱形的pie,半径比一定相同,但高都为1, 邀请了f个朋友,加上自己一共f+1人,需要将n个pie分给f+1个人 要求:每个人分得的pie尺寸要一样大, 并且同一个人所分的pie要是从同一个pie上得到的,n个pie分完后可以有剩余 求:每个人最多可以分多少 分析:因为同一个人所分的pie都来自同一个pie, 若每个人所分的最大体积为a,那么比a小的pie肯定得舍弃. 将每个人最多分得的pie看成半径为r的圆柱,则最大尺寸为PI*r*r*1

poj 1905 (二分查找)

链接:poj 1905 截取自某大牛的blog,详情请关注:链接:Enumz 题意:一根两端固定在两面墙上的杆长度为L,受热弯曲后变弯曲, 长度L′=(1+nc)*L,求前后两个状态的杆的中点位置的距离 分析:设L′对应的半径为r,弧长为2α,要求的距离为x 根据直角三角形的性质可得: 根据弧长公式L′=2αr可得 有勾股定理得出: 代入得: 其为单调函数,二分求解即可. PS:卡精度 特判若输入存在0,则直接输出0.000 #include<stdio.h> #include<math

LightOJ 1307 Counting Triangles 二分查找

[题解整理]二分题 题目类型: 二分查找: 二分答案. 大致解题思路: 查找注意有序和返回值: 浮点数注意精度: 整数注意返回值,建议另外维护一个变量,用于储存可行解. 题目 分类 传送门 WA点 poj 2785 二分查找 题解 lightoj 1088 二分查找 题解 lightoj 1307 二分查找 题解 longlong poj 2456 整数二分答案 题解 poj 3104 整数二分答案 题解 poj 3258 整数二分答案 题解 poj 3273 整数二分答案 题解 lightoj

poj 2452(RMQ+二分查找)

题目链接: http://poj.org/problem?id=2452 题意:在区间[1,n]上找到满足 a[i]<a[k]<a[j] (i<=k<=j) 的最大子区间 (j-i)如不存在输出 -1. 思路:枚举i,找到 i右边第一个不大于(不是小于) a[i]的数a[k](二分查找+RMQ某段区间的最小值是否小于a[i].最后确定到一个点),于是我们可以得到在区间[i,k-1]范围内的数都会大于 a[i] ,所以对于下标i,它对应的最长区间必定在[i,k-1]之间. 所以,我们

poj 1151 Atlantis 二分查找+离散化

Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17464   Accepted: 6654 Description There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of

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

POJ 1064 Cable master 一开始把 int C(double x) 里面写成了  int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条件写错了,wa了n次,当 c(mid)<=k时,令ub=mid,这个判断是错的,因为要找到最大切割长度,当满足这个条件时,可能已经不是最大长度了,此时还继续缩小区间,自然就wa了,(从大到小递减,第一次满足这个条件的值,就是最大的值),正确的判断是当 c(mid)<k时,令ub=mid,这样循环1

POJ 2289--Jamie&#39;s Contact Groups【二分图多重匹配问题 &amp;&amp;二分查找最大值的最小化 &amp;&amp; 最大流】

Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 6902   Accepted: 2261 Description Jamie is a very popular girl and has quite a lot of friends, so she always keeps a very long contact list in her cell phone. The con

POJ 3122 Pie 二分答案

Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9653   Accepted: 3478   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 v

[ACM] poj 2456 Aggressive cows (二分查找)

Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5436   Accepted: 2720 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,...

POJ 3663 Costume Party (二分查找)

Costume Party Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12297   Accepted: 4891 Description It's Halloween! Farmer John is taking the cows to a costume party, but unfortunately he only has one costume. The costume fits precisely two