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

 
题目意思:

就是公平地分披萨pie

我生日,买了n个pie,找来f个朋友,那么总人数共f+1人

每个pie都是高为1的圆柱体,输入这n个pie的每一个尺寸(半径),如果要公平地把pie分给每一个人(就是所有人得到的pie尺寸一致,但是形状可以不同),而且每个人得到的那份pie必须是从同一个pie上得到的

做法:

输入的是朋友的数量f,分pie是分给所有人,包括自己在内共f+1人

下界low=0,即每人都分不到pie

上界high=maxsize,每人都得到整个pie,而且那个pie为所有pie中最大的

(上界就是 n个人n个pie,每个pie还等大)

对当前上下界折中为mid,计算"如果按照mid的尺寸分pie,能分给多少人"

求某个pie(尺寸为size)按照mid的尺寸,能够分给的人数,就直接size / mid,舍弃小数就可以

code:

#include<stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include<string.h>
using namespace std;
#define max_v 10005
double PI=acos(-1.0);
double v[max_v];
int n,f;
bool test(double x)
{
int num=;
for(int i=;i<n;i++)
{
num+=int(v[i]/x);////每一个蛋糕的体积除以x 必须是完整蛋糕所以int();
}
if(num>=f+) //当人数大于等于f+1时说明蛋糕可以更大
return true;
else
return false;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int r;
cin>>n>>f;
double left=,right=,mid=;
for(int i=;i<n;i++)
{
cin>>r;
v[i]=PI*r*r*1.0;//体积都为1
right=max(right,v[i]);//最大蛋糕就是右边界
}
while(fabs(right-left)>1e-)
{
mid=(right+left)*0.5;
if(test(mid))
{
left=mid;//否则mid偏小,下界优化
}else
{
right=mid;//说明mid偏大,上界优化
}
}
printf("%.4f\n",mid);
}
return ;
}

POJ 3122 Pie(二分+贪心)的更多相关文章

  1. POJ 3122 Pie (贪心+二分)

    My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...

  2. POJ 3122 Pie 二分枚举

    题目:http://poj.org/problem?id=3122 这个题就好多了,没有恶心的精度问题,所以1A了.. #include <stdio.h> #include <ma ...

  3. POJ 3122 Pie 二分答案

    题意:给你n个派,每个派都是高为一的圆柱体,把它等分成f份,每份的最大体积是多少. 思路: 明显的二分答案题-- 注意π的取值- 3.14159265359 这样才能AC,,, //By Sirius ...

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

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

  5. poj 3122 (二分查找)

    链接:http://poj.org/problem?id=3122 Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1 ...

  6. POJ - 3122 Pie(二分)

    http://poj.org/problem?id=3122 题意 主人过生日,m个人来庆生,有n块派,m+1个人(还有主人自己)分,问每个人分到的最大体积的派是多大,PS每 个人所分的派必须是在同一 ...

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

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

  8. POJ 3122 Pie【二分答案】

    <题目链接> 题目大意: 将n个半径不一但是高度为1的蛋糕分给 F+1个人,每个人分得蛋糕的体积应当相同,并且需要注意的是,每个人分得的整块蛋糕都只能从一个蛋糕上切下来,而不是从几个蛋糕上 ...

  9. POJ 3122 Pie

    题目大意: 给出n个pie的直径,有f+1个人,如果给每人分的大小相同(形状可以不同),每个人可以分多少.要求是分出来的每一份必须出自同一个pie,也就是说当pie大小为3,2,1,只能分出两个大小为 ...

随机推荐

  1. Jquery判断checkbox选中状态

    jQuery v3.3.1 <input type="checkbox" id="ch"> 判断 $('#ch').is(':checked'); ...

  2. weblogic11g(10.3.6)部署war包时,解决jar包冲突的超简方案

    亲测有效:weblogic11g(10.3.6) + jdk7,打包使用jdk7或jdk8,注意weblogic用的jdk和打包时jdk的兼容. 分别配置web项目下pom.xml和weblogic. ...

  3. OkHttp完全解析之整体调用流程

    前言:阅读好的代码如同观赏美景一样的美妙 OkHttp是一个Square公司在github开源的Java网络请求框架,非常流行.OkHttp 的代码并不是特别庞大,代码很多巧妙的实现,非常值得学习. ...

  4. 判断sql是否存在特定的对象

    1 判断数据库是否存在if exists (select * from sys.databases where name = '数据库名') drop database [数据库名] 2 判断表是否存 ...

  5. springmvc封装list个数限制问题

    提交一颗树,三级区域个数大于1000个导致提交失败!!! org.springframework.beans.InvalidPropertyException: Invalid property 'd ...

  6. 安卓app应用开发资料

    android 配置文件画图 http://blog.csdn.net/loongggdroid/article/details/46687589 android下拉刷新控件 https://gith ...

  7. 用C读取INI配置文件

    http://blog.csdn.net/chexlong/article/details/6818017 #define CONF_FILE_PATH "Config.ini" ...

  8. DBGridEh常用技巧

    一.增加多表头显示方式 DBGridEh1.UseMultiTitle:=True; //打开多标题显示方式 DBGridEh1.Columns[].Title.Caption:='员工编号'; // ...

  9. 旋转数组的最小数字(C++ 和 Python 实现)

    (说明:本博客中的题目.题目详细说明及参考代码均摘自 “何海涛<剑指Offer:名企面试官精讲典型编程题>2012年”) 题目 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的 ...

  10. SQL Server 2016 ->> T-SQL新特性

    1) TRUNCATE表分区而不是整表 CREATE TABLE dbo.TruncatePartitionTest ( PrtCol INT, Col2 ) ) ON [myPS1](PrtCol) ...