HDU 1969 Pie(二分法)
My 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.
Input
One line with a positive integer: the number of test cases. Then for each test case: • One line with two integers N and F with 1 ≤ N, F ≤ 10000: the number of pies and the number of friends. • One line with N integers ri with 1 ≤ ri ≤ 10000: the radii of the pies.
Output
For 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 oating point number with an absolute error of at most 10−3 .
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个他的朋友,他家里有n个Pie,主人希望把Pie分出F+1份,体积相同(包括主人),所有的Pie不需要都分完,问你每个人最大能分到多大体积的Pie。
主要是猜那个二分最小值x,对,就是猜。
#include <iostream>
#include <cstdio>
#include<cmath>
using namespace std;
double pi=acos(-1.0); // 圆周率的表示。。。
int T,n,f;
double b[];
int juge(double x)
{
int total =;
for(int i=; i<=n; i++)
{
total+=int(b[i]/x);
}
if(total>f)
return ;
else
return ;
}
int main()
{
double l,r,mid,rad;
cin>>T;
while(T--)
{
cin>>n>>f;
double sum=;
for(int i =; i<=n; i ++)
{
cin>>rad;
b[i]=rad*rad*pi;
sum+=b[i];
}
l=;
double r=sum/(f+);
while(r-l>0.0001) // 此题精度小数点后四位
{
mid=(l+r)/;
if(juge(mid))
l=mid;
else
r=mid;
}
printf("%.4lf\n",mid);
}
return ;
}
HDU 1969 Pie(二分法)的更多相关文章
- hdu 1969 Pie (二分法)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- hdu 1969 Pie(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others) Me ...
- HDU 1969 Pie(二分查找)
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- HDU 1969(二分法)
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 ...
- HDU 1969 Pie(二分,注意精度)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 1969 Pie【二分】
[分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...
- 题解报告: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 ...
随机推荐
- wordpress迁移
从一个地方搬到另一个窝,我必定会带着我的Wordpress,这就涉及到博客的迁移了.首先申明,该文非原创,放在这里主要是为了方便自己日后再次需要转移博客时,能很快锁定文章目标. 这篇文章主要介绍怎样将 ...
- Apache rewrite 详解
用rewrite可实现的部分:URL根目录搬迁,多目录查找资源,阻止盗连你的图片,拒绝某些主机访问,基于时间重写,据浏览器类型重写,动态镜像远程资源,外部重写程序模板,等等 详见下表: 目标 重写设置 ...
- 你真的会用 SDWebImage?
SDWebImage作为目前最受欢迎的图片下载第三方框架,使用率很高.但是你真的会用吗?本文接下来将通过例子分析如何合理使用SDWebImage. 使用场景:自定义的UITableViewCell上有 ...
- Android_ViewFlipper
xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...
- 关于事件监听机制的总结(Listener和Adapter)
记得以前看过事件监听机制背后也是有一种设计模式的.(设计模式的名字记不清了,只记得背后实现的数据结构是数组.) 附上事件监听机制的分析图: 一个事件源可以承载多个事件(只要这个事件源支持这个事件就可以 ...
- 记工作中的git遇到的问题
看了 git 回退到某版本后,再在此版本上更新,无法push 操作前,我备份了修改了目录,准备建一个分支进行操作 我在本地revert了一次,commit到了远程仓库.然后上个版本的修改给恢复了... ...
- videojs 动态加载视频
VideoJS dynamic source change via RESTful API 'Undefined' issue with changing RTMP source on compres ...
- apk 反编译记录
反编译资源文件 工具:apktool 使用命令:java -jar apktool.jar d test.apk apktool官网下载地址:github 反编译classes.dex文件 工具:de ...
- New Lantern Version Available Upgrade Lantern for improved blocking resistance!
New Lantern Version Available Upgrade Lantern for improved blocking resistance! The new version: is ...
- 从V$SQL_PLAN中FORMAT执行计划
10G版本 select sql_id from v$sqlarea where sql_text like'%xxx%'; select * from v$sql_plan where sql_i ...