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 ...
随机推荐
- ios存储 plist 偏好设置 自定义对象存储
1,plist Plist注意:不能存储自定义对象 Plist:数组和字典, 如何判断一个对象能不能使用Plist,就看下有没有writeToFile 获取应用的文件夹(应用沙盒) NSString ...
- Java读取一个文件并打印到控制台上
package test9; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundExcept ...
- 五个在XML文档中预定义好的实体
下面是五个在XML文档中预定义好的实体: < < 小于号 > > 大于号 & & 和 ' ' 单引号 " " 双引号 实体 ...
- JavaScript高级程序设计(第三版)学习笔记1~5章
第2章,在html中使用JavaScript Html引入外部js脚本 <script type="text/javascript" src="test.js&qu ...
- Spring的servlet context和application context
Spring lets you define multiple contexts in a parent-child hierarchy. The applicationContext.xml def ...
- java程序执行顺序
原来自己一直都没弄明白Java程序的执行顺序问题,今天,自己写了个测试,果然与自己考虑的有差距 测试代码: 一个父类Animal 一个子类Dog 测试类Test 运行结果: 所以执行顺序是: 父类An ...
- gwt-问题解决
最近在看gwt,写了个demo,但是总是出问题,困扰了好几天,后台也没报错,但就是加载不出来 第一次编译以后是可以的,但是改了代码后就不行了,后台也没报错,google了好长时间也没出来. 于是换了个 ...
- Android 百度地图开发之一(Hello BaiDu Map)
之前也接触过百度地图的开发,但那是在网上找的案例或代码,而且是比较老的版本.打算重新学习一下百度地图的开发. 本次使用的百度地图的版本是 Android SDK v3.0.0 本篇文章主要讲述百度地图 ...
- Sql Server通过BCP数据导出Excel
1.1. bcp的主要参数介绍 bcp共有四个动作可以选择. (1) 导入. 这个动作使用in命令完成,后面跟需要导入的文件名. (2) 导出. 这个动作使用out命令完成,后面跟需要导出的文件名. ...
- 使用netbeans 搭建 JSF+SPRING 框架
spring版本使用4,jsf版本2.2 jsf的配置文件faces-config.xml <?xml version='1.0' encoding='UTF-8'?> <faces ...