*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 ...
随机推荐
- jsp动作元素之forward指令
forward指令用于将页面响应转发到另外的页面.既可以转发到静态的HTML页面,也可以转发到动态的JSP页面,或者转发到容器中的Servlet. forward指令格式如下: <jsp:for ...
- 【Go入门教程6】interface(interface类型、interface值、空interface{}、嵌入interface、反射)
interface Go语言里面设计最精妙的应该算interface,它让面向对象,内容组织实现非常的方便,当你看完这一章,你就会被interface的巧妙设计所折服. 什么是interface 简单 ...
- ASP.NET Core--授权过滤器
翻译如下: 目前,我们正在从事这方面工作. 我们欢迎您的加入,以帮助塑造范围和方法.您可以跟踪状态并在此提供的输入问题在GitHub上. 如果你想查看初稿并在此主题的大纲,请留下注意到在您的联系信息的 ...
- linux c 笔记-4 工程项目阅读推荐
作者:周子涵链接:https://www.zhihu.com/question/27705862/answer/37738315来源:知乎著作权归作者所有,转载请联系作者获得授权. 转自网上不知道什么 ...
- 关于git的简单实用命令
时代在进步啊,现在已经不是svn的时代了,好多人都在使用git.所以自己也稍微学习了下git的使用. 常见的通过git提交代码步骤: git status :查看文件状态 :该命令显示你工程内修改的所 ...
- MySQL 5.7 mysqlpump 备份工具说明
背景: MySQL5.7之后多了一个备份工具:mysqlpump.它是mysqldump的一个衍生,mysqldump就不多说明了,现在看看mysqlpump到底有了哪些提升,可以查看官方文档,这里针 ...
- 四种常见的 POST 提交数据方式
HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE.CONNECT 这几种.其中 POST 一般用来向服务端提交数据,本文 ...
- MySQL批量UPDATE多行记录
UPDATE categories SET display_order = CASE id WHEN 1 THEN 3 WHEN 2 THEN 4 ...
- mysql 常用语句
1,查看索引使用情况的语句: explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上explai ...
- CSS实现背景透明,文字不透明,兼容所有浏览器
11.11是公司成立的日子,16岁啦,我呢3岁半,感谢公司给了这样一个平台,让我得以学习和成长,这里祝愿公司发展越来越好~ 进入主题,每年11月11号是光棍节,产生于校园,本来只是一流传于年轻人的娱乐 ...