Pie(二分)
ime Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 8930 | Accepted: 3235 | Special Judge |
Description

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 题意:过生日,有f+1个人(加上主人),去分n个尺寸不同的圆柱型的pie,其高为1.要注意n个pie分别不同,每个人分得的必须是同一个pie上的。问平均每个人最多可分得多少。
思路:二分,先找出上下界,下界为0,上界是n个pie中尺寸最大的那个,即每个人得到整个pie,而且是最大的那个。
不断二分,若求出的人数大于f+1,说明现在分得的pie小了,更改min值,否则,更改max值;
#include<stdio.h>
#include<math.h> const double PI = 3.1415926535898;
const double eps = 1e-; int main()
{
int test;
scanf("%d",&test);
while(test--)
{
int n,f;
double V[];
double min,max,mid;
min = 0.0;
max = 0.0; scanf("%d %d",&n,&f);
f += ;//加上主人共f+1人;
for(int i = ; i < n; i++)
{
scanf("%lf",&V[i]);
V[i] = V[i]*V[i];
if(max < V[i])
max = V[i];
} while(max - min > eps)
{
mid = (max+min)/;
int people = ;
for(int i = ; i < n; i++)
people += V[i]/mid;//每个人分得的pie必须来自于同一个pie,直接取整就行; if(people < f)
max = mid;
else min = mid;
}
double ans = PI*mid;
printf("%.4lf\n",ans);
}
return ;
}
Pie(二分)的更多相关文章
- HDU 1969 Pie(二分查找)
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- HDU 1969 Pie(二分,注意精度)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 【POJ 3122】 Pie (二分+贪心)
id=3122">[POJ 3122] Pie 分f个派给n+1(n个朋友和自己)个人 要求每一个人分相同面积 但不能分到超过一个派 即最多把一整个派给某个人 问能平均分的最大面积 二 ...
- Pie(二分)
http://poj.org/problem?id=3122 题意:将n个圆柱体的不同口味的pie分给m个人,要求每个人分得的pie必须体积相同,且来自于一块pie(即:只分得一种口味的pie),求最 ...
- Pie(二分POJ3122)
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12985 Accepted: 4490 Special Ju ...
- PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...
- 【hoj】2651 pie 二分查找
二分查找是一个非常主要的算法,针对的是有序的数列,通过中间值的大小来推断接下来查找的是左半段还是右半段,直到中间值的大小等于要找到的数时或者中间值满足一定的条件就返回,所以当有些问题要求在一定范围内找 ...
- HDU1969:Pie(二分)
Pie Time Limit : 5000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissio ...
- B - Pie (二分)
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...
- UVaLive 3635 Pie (二分)
题意:有f+1个人来分n个圆形派,每个人得到的必须是一个整块,并且是面积一样,问你面积是多少. 析:二分这个面积即可,小了就多余了,多了就不够分,很简单就能判断. 代码如下: #pragma comm ...
随机推荐
- 去掉android点击事件产生的半透明蓝色背景
在wap开发过程当中,当你点击一个链接或者通过Javascript定义的可点击元素的时候,它就会出现一个半透明的蓝色背景,若要重设这个表现 ,可以利用css3: *{ -webkit-tap-high ...
- UITableView beginUpdate和endUpdate使用的前提
转载地址:http://blog.csdn.net/vieri_ch/article/details/46893023 UITableView有两个方法,用于单元格动画变化的方法,beginUpdat ...
- 1 - SQL Server 2008 之 使用SQL语句创建具有约束条件的表
约束条件分为以下几种: 1)非空约束,使用NOT NULL关键字: 2)默认值约束,使用DEFAULT关键字: 3)检查约束,使用CHECK关键字: 4)唯一约束,使用UNIQUE关键字: 5)主键约 ...
- Linux shell用法和技巧
使用Linux shell是我每天的基本工作,但我经常会忘记一些有用的shell命令和l技巧.当然,命令我能记住,但我不敢说能记得如何用它执行某个特定任务.于是,我开始在一个文本文件里记录这 ...
- python版本简历
- 使用java注解的例子有没有
使用java注解的例子 参考文档:http://www.cnblogs.com/pepcod/archive/2013/02/20/2918719.html http://www.shaoqun.co ...
- javascript ~~ 符号的使用
其实是一种利用符号进行的类型转换,转换成数字类型 大概是这样滴: ~~true == 1 ~~false == 0 ~~"" == 0 ~~[] == 0 ~~undefined ...
- mysql - 初探
1,查询所有数据库名称: show databases; 2,查询所有表: use database_name; show tables; 3,查询表中的所有字段: desc table_name;
- Linux软件
网上下载:Chrome Browser for Linux; sqlite; WPS; symbol-fonts; 软件中心:Terminator; Code::Blocks IDE; 新立得软件 ...
- vs2010安装路径解决不能修改的方法
环境:win7 64位 解决:网上说需要卸载以下4项 Microsoft Visual Studio Tools for Applications 2.0 - ENU Microsoft Visual ...