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 ...
随机推荐
- linux文件夹操作(及模糊搜索)
mkdir 文件夹名称 :创建文件夹 touch 文件名称 : 创建文件 给文件夹或文件授权 chmod -R 777 文件夹名称 : 递归给文件夹授读写执行权限 chmo ...
- C#_delegate - 调用列表 计算阶乘
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Dele ...
- java中public等权限问题和final的使用
1.public:public表明该数据成员.成员函数是对所有用户开放的,所有用户都可以直接进行调用 2.private:private表示私有,私有的意思就是除了class自己之外,任何人都不可以直 ...
- Linux基础(一)
一.安装linux系统可以用的5种方法 1.光盘 2.硬盘 3.NFS 映像 4.FTP 5.HTTP 硬盘安装分两种情况: A.是从Win系统上安装 B.是从别的Linux启动安装 这里介绍大多数人 ...
- linux__升级java版本
java下载地址:http://www.oracle.com/index.html 使用which java查看到,Java的环境变量指向的还是/usr/bin/java,问题找到了.于是就进行了下面 ...
- 关于MyBatis的工作流程
1.从一个jdbc程序开始 public static void main(String[] args) { Connection connection = null; PreparedStateme ...
- 【转】spring - ioc和aop
[转]spring - ioc和aop 1.程序中为什么会用到spring的ioc和aop 2.什么是IOC,AOP,以及使用它们的好处,即详细回答了第一个问题 3.原理 关于1: a:我们平常使用对 ...
- 【转】ArrayList的toArray,也就是list.toArray[new String[list.size()]];,即List转为数组
[转]ArrayList的toArray ArrayList提供了一个将List转为数组的一个非常方便的方法toArray.toArray有两个重载的方法: 1.list.toArray(); 2.l ...
- 从V$SQL_PLAN中FORMAT执行计划
10G版本 select sql_id from v$sqlarea where sql_text like'%xxx%'; select * from v$sql_plan where sql_i ...
- 【HTTPS】Https和SSL学习笔记(二)
此文讲述证书的相关信息,参考文章链接http://www.guokr.com/post/116169/ 一. 证书的类型 常用的几种证书如下: (1) SSL证书,用于加密HTTP (2) 代码签名证 ...