http://acm.hdu.edu.cn/showproblem.php?pid=1969

Pie

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

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
#include<stdio.h>
#include<math.h>
#define pi acos(-1.0)
int n,f;
double a[10005];
int cmp(double v)
{
int i,sum=0;
for(i=0;i<n;i++)
sum+=int(a[i]/v);
if(sum>=f)
return 1;
else
return 0;
}
int main()
{
int t,i;
double size,right,left,mid,sum,temp;;
scanf("%d",&t);
while(t--)
{
sum=0;
scanf("%d%d",&n,&f);
f++;
for(i=0;i<n;i++)
{
scanf("%lf",&temp);
a[i]=pi*temp*temp;
sum+=a[i];
}
size=sum/f;
left=0;right=size;
while(right-left>1e-6)
{
mid=(right+left)/2;
if(cmp(mid))
left=mid;
else
right=mid;
}
printf("%.4lf\n",mid);
}
return 0;
}
 

HDU-1969 Pie的更多相关文章

  1. hdu 1969 Pie(二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others)    Me ...

  2. HDU 1969 Pie(二分法)

    My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...

  3. hdoj 1969 Pie【二分】

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  4. HDU 1969 Pie(二分查找)

    Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...

  5. HDU 1969 Pie(二分搜索)

    题目链接 Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pi ...

  6. HDU 1969 Pie(二分,注意精度)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  7. hdu 1969 Pie (二分法)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  8. HDU 1969 Pie【二分】

    [分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...

  9. 题解报告:hdu 1969 Pie(二分)

    Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...

  10. hdu 1969 pie 卡精度的二分

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

随机推荐

  1. [FTP] FTPClient--FTP操作帮助类,上传下载,文件,目录操作 (转载)

    点击下载 FTPClient.zip 这个类是关于FTP客户端的操作1.构造函数 2.字段 服务器账户密码3.属性4.链接5.传输模式6.文件操作7.上传和下载8.目录操作9.内容函数看下面代码吧 / ...

  2. Android - 服务器json数据交互.

    一,服务器端 服务器端使用的是Servlet,封装json对象使用的 'json-lib-2.2.2-jdk15.jar,ezmorph-1.0.4.jar,commons-logging-1.1.j ...

  3. Spring处理id相同的bean

    http://www.360doc.com/content/13/1018/05/41237_322247510.shtml(应该可以解决) http://www.2cto.com/kf/201601 ...

  4. SQL Server中Id自增列的最大Id是多少

    什么是自增列 在SQL Server中可以将Id列设为自增.即无需为Id指定值,由SQL Server自动给该列赋值,每新增一列Id的值加一,初始值为1. 需要注意的是即使将原先添加的所有数据都删除, ...

  5. linunx 定位最耗资源的进程

    [oracle@topbox bdump]$ ps -ef|grep “(LOCAL=NO)”|sort -rn -k 8,8|head -10oracle    9402     1 67 09:1 ...

  6. iOS中的几种定时器详解

    在软件开发过程中,我们常常需要在某个时间后执行某个方法,或者是按照某个周期一直执行某个方法.在这个时候,我们就需要用到定时器. 然而,在iOS中有很多方法完成以上的任务,经过查阅资料,大概有三种方法: ...

  7. Lucene初步搜索

    Lucene在创立索引后,要进行搜索查询 搜索大概需要5部, 1,读取索引. 2,查询索引. 3,匹配数据. 4,封装匹配结果. 5,获取需要的值. 语言表达能力不好,大概就是分着几部吧. /** * ...

  8. 简单的背包变形HDU1203,HDU2955

    今天一直在写背包,不过中间停了一段时间在写shell. 一直在做01背包.今天做了这两题很相似的背包 首先是HDU1203 Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要 ...

  9. Linux的more、less

    2.more 文件内容或输出查看工具: more 是我们最常用的工具之一,最常用的就是显示输出的内容,然后根据窗口的大小进行分页显示,然后还能提示文件的百分比: de>[root@localho ...

  10. 《paste命令》-linux命令五分钟系列之二十

    本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...