题解报告:hdu 1969 Pie(二分)
Problem 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
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
const double pi=acos(-1.0);
const double eps=1e-7;
int t,n,f,cnt;double L,R,mid,r,maxsize,s[maxn];
int main(){
while(~scanf("%d",&t)){
while(t--){
scanf("%d%d",&n,&f);f+=;maxsize=0;
for(int i=;i<n;++i)scanf("%lf",&r),s[i]=pi*r*r,maxsize=max(maxsize,s[i]);//找出最大的馅饼面积
L=,R=maxsize;
while(R-L>eps){//因为只保留4位小数,所以精度控制在1e-7内即可(1e-8会超时)
mid=(R+L)/,cnt=;
for(int i=;i<n;++i)cnt+=floor(s[i]/mid);//取整
if(cnt>=f)L=mid;//如果发现可以分的人更多,那么就往右边找
else R=mid;//否则说明只能找小的尺寸,即往左边找
}
printf("%.4f\n",mid);
}
}
return ;
}
题解报告:hdu 1969 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 ...
- HDU 1969 Pie [二分]
1.题意:一项分圆饼的任务,一堆圆饼共有N个,半径不同,厚度一样,要分给F+1个人.要求每个人分的一样多,圆饼允许切但是不允许拼接,也就是每个人拿到的最多是一个完整饼,或者一个被切掉一部分的饼,要求你 ...
- (step4.1.2)hdu 1969(Pie——二分查找)
题目大意:n块馅饼分给m+1个人,每个人的馅饼必须是整块的,不能拼接,求最大的. 解题思路: 1)用总饼的体积除以总人数,得到每个人最大可以得到的V.但是每个人手中不能有两片或多片拼成的一块饼. 代码 ...
- hdu 1969 Pie(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others) Me ...
- HDU 1969 Pie【二分】
[分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...
- hdu 1969 pie 卡精度的二分
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 1969 Pie(二分法)
My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...
- HDU 1969 Pie(二分搜索)
题目链接 Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pi ...
随机推荐
- (转载)常用的Mysql数据库操作语句大全
打开CMD,进入数据库命令:mysql -hlocalhost -uroot -p 退出数据库:exit 用户管理: 1.新建用户: >CREATE USER name IDENTIFIED B ...
- ECMAScript学习笔记
1. ECMAScript不存在块级作用域,因此在循环内部定义的变量,在循环外也是可以访问的 eg: var count =10; fpr(var i=0; i<count; i++){ ale ...
- 新建web项目时css注意事项
初始化css ,如设置body的margin,padding值,button:hover的pointer手型,li dd的list-style,a的下划线等. 最好将常用的初始化css文件整合在一起, ...
- spring cloud 启动报错-must be declared as an @AliasFor [serviceId], not [name].
项目加入FeignClient后再启动就报错,具体报错信息如下: org.springframework.core.annotation.AnnotationConfigurationExceptio ...
- 传统maven项目创建
转自:https://blog.csdn.net/wangfengtong/article/details/77098238 需求表均同springmvc案例 此处只是使用maven 注意,以下所有需 ...
- HDU 1081:To The Max
To The Max Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- 【摘抄】u3d|unity学习教程与方法
小编,因为下面这句话,还是决定,只摘链接地址(来自百度经验): http://jingyan.baidu.com/article/19192ad820f17be53e570715.html 经验内容仅 ...
- 书写优雅的shell脚本(一)- if语句
使用unix/linux的程序人员几乎都写过shell脚本,但这其中很多人都是为了完成功能而在网上找代码段,这样写出来的shell脚本在功能方面当然是没有什么问题,但是这样的方式不能写出优雅的shel ...
- Python测试框架doctest
doctest是python自带的一个模块.本博客将介绍doctest的两种使用方式:一种是嵌入到python源码中,另外一种是放到一个独立文件. doctest 的概念模型 在python的官方文档 ...
- py-day15_css+js_初
css+js_初 一.鼠标移动变色 <!DOCTYPE html> <html lang="en"> <head> <meta chars ...