Pie

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10043    Accepted Submission(s): 3637

Problem Description
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 <= 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
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 floating 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
 
Source
题意:
共有n个半径不同的馅饼,f+1个人分,每个人只能分一块,每个人分得的面积要相同,问每个人最大能分多少。
代码:

 //由于每个人只能分一块,可以以最大的那块面积为上界,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 二分的更多相关文章

  1. HDU2199,HDU2899,HDU1969,HDU2141--(简单二分)

    二分是一种很有效的减少时间开销的策略, 我觉得单列出二分专题有些不太合理, 二分应该作为一中优化方法来考虑 这几道题都是简单的使用了二分方法优化, 二分虽然看似很简单, 但一不注意就会犯错. 在写二分 ...

  2. HDU1969:Pie(二分)

    Pie Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissio ...

  3. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  4. BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]

    2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 3352  Solved: 919[Submit][Stat ...

  5. 整体二分QAQ

    POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...

  6. [bzoj2653][middle] (二分 + 主席树)

    Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...

  7. [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 ...

  8. [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 ...

  9. jvascript 顺序查找和二分查找法

    第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...

随机推荐

  1. PHP获取当前域名$_SERVER['HTTP_HOST']和$_SERVER['SERVER_NAME']的区别

    开发站群软件,用到了根据访问域名判断子站点的相关问题,PHP获取当前域名有两个变量 $_SERVER['HTTP_HOST'] 和 $_SERVER['SERVER_NAME'],两者的区别以及哪个更 ...

  2. 最近使用oracle的笔记和少量的正则表达式

    用户.表空间.表:    一个用户一般给予一个表空间,可以多个用户共同管理一个表空间    一个表空间会有多张表对于权限的控制:    在数据库中在人员菜单与需要浏览的文件之间做权限设置能否浏览,可以 ...

  3. sdcms留言提交

    引入这两个js <script src="{webroot}lib/validator/jquery.validator.js"></script>< ...

  4. dos 操作显示 > nul 2>nul

    1>nul 屏蔽操作成功显示的信息,但是出错还是会显示(同 >nul)2>nul 屏蔽操作失败显示的信息,但是成功还是会显示>nul 2>nul 就是正确的错误的一起屏蔽 ...

  5. C# Bitmap deep copy

    今天在研究一个关于 Bitmap deep copy 的问题, 经过一系列的查询,在StackOverFlow上面找到了答案,遂记录下来: public static Bitmap DeepCopyB ...

  6. OC编程之道-创建对象之工厂方法

    一 何为工厂方法模式?(what) 定义创建对象的接口,让子类决定实例化哪一个类,工厂方法是的一个类的实例化延迟到其子类. 工厂方法创建的对象拥有一组共同的行为,所以往类层次结构中引入新的具体产品并不 ...

  7. C Primer Plus_第6章_循环_编程练习

    1.题略 #include int main(void) { int i; char ch[26]; for (i = 97; i <= (97+25); i++) { ch[i-97] = i ...

  8. ajax提交form表单资料详细汇总

    一.ajax提交form表单和不同的form表单的提交主要区别在于,ajax提交表单是异步提交的,而普通的是同步提交的表单.通过在后台与服务器进行少量数据交换,ajax 可以使网页实现异步更新.这意味 ...

  9. ios升级<注:来着微信平台>

    <来着微信平台>  http://mp.weixin.qq.com/s?__biz=MjM5NTIyNTUyMQ==&mid=2709545194&idx=1&sn ...

  10. 由一段字符串中查找URL引出——正则表达式

    需求很简单,是从一段文本中匹配出其中的超链接.基本的做法就是用正则表达式去匹配.但是有这样一个问题. 网上大部分的识别URL的正则表达式url末尾有空格的情况下可以正确识别.比如这样的情况: &quo ...