*HDU1969 二分
Pie
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10043 Accepted Submission(s): 3637
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.
---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.
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).
//由于每个人只能分一块,可以以最大的那块面积为上界,0位下界,二分寻找一个面积,用每一张馅饼除以这个面积就会得到能分几个人,
//就这样不断二分,等于时不结束,注意二分精度不能太大会超时。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double PI=acos(-1.0);
int t,n,f;
double a[];
int chak(double mid)
{
int sum=;
for(int i=;i<=n;i++)
sum+=(int)(a[i]/mid);
return sum;
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&f);
f++;
double tem=;
for(int i=;i<=n;i++)
{
scanf("%lf",&a[i]);
a[i]=a[i]*a[i]*PI;
if(a[i]>tem) tem=a[i];
}
double lef=,rig=tem,mid;
while(rig-lef>0.0000001)
{
mid=(lef+rig)/;
int sum=chak(mid);
if(sum>=f) lef=mid;
if(sum<f) rig=mid;
}
printf("%.4lf\n",mid);
}
return ;
}
*HDU1969 二分的更多相关文章
- HDU2199,HDU2899,HDU1969,HDU2141--(简单二分)
二分是一种很有效的减少时间开销的策略, 我觉得单列出二分专题有些不太合理, 二分应该作为一中优化方法来考虑 这几道题都是简单的使用了二分方法优化, 二分虽然看似很简单, 但一不注意就会犯错. 在写二分 ...
- HDU1969:Pie(二分)
Pie Time Limit : 5000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissio ...
- BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8748 Solved: 3835[Submi ...
- BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]
2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 3352 Solved: 919[Submit][Stat ...
- 整体二分QAQ
POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...
- [bzoj2653][middle] (二分 + 主席树)
Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...
- [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二
Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...
- [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值
Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...
- jvascript 顺序查找和二分查找法
第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...
随机推荐
- [MapReduce] Google三驾马车:GFS、MapReduce和Bigtable
声明:此文转载自博客开发团队的博客,尊重原创工作.该文适合学分布式系统之前,作为背景介绍来读. 谈到分布式系统,就不得不提Google的三驾马车:Google FS[1],MapReduce[2],B ...
- 倾力总结40条常见的移动端Web页面问题解决方案
1.安卓浏览器看背景图片,有些设备会模糊. 用同等比例的图片在PC机上很清楚,但是手机上很模糊,原因是什么呢? 经过研究,是devicePixelRatio作怪,因为手机分辨率太小,如果按照分辨率 ...
- oss文件删除策略
当你想删除oss服务中某个bucket下的文件夹时,文件夹中又包含了太多文件,递归删除太过耗时,又必须删除时,此时就要用oss的文件删除策略,如下所示: OSSClient client = new ...
- Path
<Path Data="M17.5,16.5 L17.5,18.5 19.5,18.5 19.5,16.5 z M11.5,16.5 L11.5,18.5 13.5,18.5 13.5 ...
- Angular2 模板语法
1. 说明 Angular2的模板用来显示组件外观,作为视图所用,用法和html语法基本一致,最简单的Angular2的模板就是一段html代码.Angular模板语法主要包括以下几个部分: l 直接 ...
- securecrt设置 (外观,中文不乱码)
最终效果图 这叫做先入为主,哈哈~~ 详细设置,action!!!! ############### 菜单栏: 选项---会话选项 一.终端---仿真 1.终端选择 linux 2.ANSI颜色 ...
- 解决weblogic.net.http.SOAPHttpsURLConnection incompatible with javax.net.ssl.HttpsURLConnection
1. 按照网上的办法,可以修改代码解决问题,但是由于我们使用的是别人的jar包,不能修改代码,: URL url = new URL(null, "https://www.baidu.&qu ...
- MapKit/CoreLocation框架 总结
MapKit/CoreLocation框架 /*英译 core:核心 track:踪迹 current:当前 statellite:卫星 hybird:混合 region:范围 annotation ...
- Swift - UITableView里的cell底部分割线左侧靠边
override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, ...
- Nginx 反代理其他搜索引擎
反向代理 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客 ...