POJ 3122 pie (二分法)
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
Sample Output
题目意思:我过生日请了f 个朋友来参加我的生日party,m个蛋糕,我要把它平均分给每个人(包括我),并且每个人只能从一块蛋糕得到自己的那一份,并且分得的蛋糕大小要一样,形状可以不一样,每块蛋糕都是圆柱,高度一样。
#include<cstdio>
#include<math.h>
double pi = acos(-1.0);
double sum,mid,le,ri,b[+],max0;
int n,f,r;
double fl(double x)
{
int su=;
for(int i = ; i < n ; i++)
{
su+=(int)(b[i]/x);
}
return su;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
sum=;
scanf("%d %d",&n,&f);
f++;
for(int i = ; i < n ; i++)
{
scanf("%d",&r);
b[i]=r*r*pi;
sum+=b[i];
}
sum=sum/f;
le=0.0;
ri=sum;
while(fabs(ri-le)>1e-)
{
mid=(le+ri)/;
if(fl(mid) >= f)
{
le=mid;
}
else
{
ri=mid;
}
}
printf("%.4f\n",le);
}
}
POJ 3122 pie (二分法)的更多相关文章
- POJ - 3122 Pie(二分)
http://poj.org/problem?id=3122 题意 主人过生日,m个人来庆生,有n块派,m+1个人(还有主人自己)分,问每个人分到的最大体积的派是多大,PS每 个人所分的派必须是在同一 ...
- POJ 3122 Pie 二分枚举
题目:http://poj.org/problem?id=3122 这个题就好多了,没有恶心的精度问题,所以1A了.. #include <stdio.h> #include <ma ...
- POJ 3122 Pie
题目大意: 给出n个pie的直径,有f+1个人,如果给每人分的大小相同(形状可以不同),每个人可以分多少.要求是分出来的每一份必须出自同一个pie,也就是说当pie大小为3,2,1,只能分出两个大小为 ...
- POJ 3122 Pie(二分+贪心)
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22684 Accepted: 7121 Special Ju ...
- POJ 3122 Pie (贪心+二分)
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...
- POJ 3122 Pie【二分答案】
<题目链接> 题目大意: 将n个半径不一但是高度为1的蛋糕分给 F+1个人,每个人分得蛋糕的体积应当相同,并且需要注意的是,每个人分得的整块蛋糕都只能从一个蛋糕上切下来,而不是从几个蛋糕上 ...
- POJ 3122 Pie( 二分搜索 )
链接:传送门 题意:一个小朋友开生日派对邀请了 F 个朋友,排队上有 N 个 底面半径为 ri ,高度为 1 的派,这 F 个朋友非常不友好,非得"平分"这些派,每个人都不想拿到若 ...
- POJ 3122 Pie 二分答案
题意:给你n个派,每个派都是高为一的圆柱体,把它等分成f份,每份的最大体积是多少. 思路: 明显的二分答案题-- 注意π的取值- 3.14159265359 这样才能AC,,, //By Sirius ...
- 【POJ 3122】 Pie (二分+贪心)
id=3122">[POJ 3122] Pie 分f个派给n+1(n个朋友和自己)个人 要求每一个人分相同面积 但不能分到超过一个派 即最多把一整个派给某个人 问能平均分的最大面积 二 ...
- poj 3122 (二分查找)
链接:http://poj.org/problem?id=3122 Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1 ...
随机推荐
- iOS 上传的图片在HTML上显示时,图片方向信息(EXIF Orientation)异常
将iPhone 6s拍摄的照片上传到服务器之后, 在Web网页上看到图片被逆时针旋转了90度, 这让我很惆怅呐! 出现这个问题其实是因为上传的图片为.jpg格式,.jpg文件含有EXIF信息, 其中E ...
- python之unittest
unittest是单元测试的一个框架 在说unittest之前,先说几个概念: TestCase 也就是测试用例 TestSuite 多个测试用例集合在一起,就是TestSuite TestLoade ...
- python之self本类对象
不知道写点啥好,讲的都太绕了 似懂非懂,貌似懂了 以后再补充吧,视频day8_3中的20——60分钟那一部分
- Discovering Gold LightOJ - 1030 || 概率与期望求法区别
#include<cstdio>//wrong_codes #include<algorithm> using namespace std; ],anss; ],T,TT,n, ...
- Jury Meeting CodeForces - 854D
Jury Meeting CodeForces - 854D 思路:暴力枚举会议开始的那一天(只需用所有向0点飞的航班的那一天+1去枚举即可),并计算所有人此情况下去0点和从0点出来的最小花费. 具体 ...
- linux下使用svn创建版本库和权限管理
linux上的svn服务端如何和本地的电脑客户端结合使用 Linux上安装SVN服务器: 第一步:检查是否已安装 # rpm -qa subversion 第二步: 通过yum命令安装svnserve ...
- 接口测试01 - HTTP协议报文结构及示例
HTTP基本架构 用一张简单的流程图来展示HTTP协议的基本架构,以便先有个基础的了解. 1)Web Client可以是浏览器.搜索引擎等等一切基于HTTP协议发起http请求的工具. 2)Web S ...
- 纯js手动分页
昨天让做个页面,后台提供所有数据,没有做好分页,需要前端js手动分页. 我参考了 http://www.cnblogs.com/jiechn/p/4095029.html 做了些许改动让分页效果更加完 ...
- DNS正、反向解析+负载均衡+智能DNS+密钥认证
主机名 IP 软件包 系统版本 内核版本 实验环境 master 192.168.30.130 bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 bind-chroot.x8 ...
- Linux遗忘命令
1.查找文件的安装目录,拿nginx来说 find /|grep nginx.conf 2. a.查询某个端口是否被占用,如8080端口 netstat –apn | grep 8080 b.查看 ...