ime Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8930   Accepted: 3235   Special Judge

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 题意:过生日,有f+1个人(加上主人),去分n个尺寸不同的圆柱型的pie,其高为1.要注意n个pie分别不同,每个人分得的必须是同一个pie上的。问平均每个人最多可分得多少。
思路:二分,先找出上下界,下界为0,上界是n个pie中尺寸最大的那个,即每个人得到整个pie,而且是最大的那个。
   不断二分,若求出的人数大于f+1,说明现在分得的pie小了,更改min值,否则,更改max值;
 #include<stdio.h>
#include<math.h> const double PI = 3.1415926535898;
const double eps = 1e-; int main()
{
int test;
scanf("%d",&test);
while(test--)
{
int n,f;
double V[];
double min,max,mid;
min = 0.0;
max = 0.0; scanf("%d %d",&n,&f);
f += ;//加上主人共f+1人;
for(int i = ; i < n; i++)
{
scanf("%lf",&V[i]);
V[i] = V[i]*V[i];
if(max < V[i])
max = V[i];
} while(max - min > eps)
{
mid = (max+min)/;
int people = ;
for(int i = ; i < n; i++)
people += V[i]/mid;//每个人分得的pie必须来自于同一个pie,直接取整就行; if(people < f)
max = mid;
else min = mid;
}
double ans = PI*mid;
printf("%.4lf\n",ans);
}
return ;
}



Pie(二分)的更多相关文章

  1. HDU 1969 Pie(二分查找)

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

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

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

  3. 【POJ 3122】 Pie (二分+贪心)

    id=3122">[POJ 3122] Pie 分f个派给n+1(n个朋友和自己)个人 要求每一个人分相同面积 但不能分到超过一个派 即最多把一整个派给某个人 问能平均分的最大面积 二 ...

  4. Pie(二分)

    http://poj.org/problem?id=3122 题意:将n个圆柱体的不同口味的pie分给m个人,要求每个人分得的pie必须体积相同,且来自于一块pie(即:只分得一种口味的pie),求最 ...

  5. Pie(二分POJ3122)

    Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12985   Accepted: 4490   Special Ju ...

  6. PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏

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

  7. 【hoj】2651 pie 二分查找

    二分查找是一个非常主要的算法,针对的是有序的数列,通过中间值的大小来推断接下来查找的是左半段还是右半段,直到中间值的大小等于要找到的数时或者中间值满足一定的条件就返回,所以当有些问题要求在一定范围内找 ...

  8. HDU1969:Pie(二分)

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

  9. B - Pie (二分)

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

  10. UVaLive 3635 Pie (二分)

    题意:有f+1个人来分n个圆形派,每个人得到的必须是一个整块,并且是面积一样,问你面积是多少. 析:二分这个面积即可,小了就多余了,多了就不够分,很简单就能判断. 代码如下: #pragma comm ...

随机推荐

  1. spring beans源码解读之--BeanFactory的注册

    beanFactory的继承关系如下图所示: (图片来源:http://www.myexception.cn/software-architecture-design/925888.html) 在上节 ...

  2. sqlserver 2008表分区操作

    表分区操作步骤 1.设计表进行分区的方案,水平分区.垂直分区 a.水平切割将减少表的行数,这样可以将历史数据归档,减少表大小,提高访问速度. b.垂直切割将分为主表和从表方式,将主要的列字段存放在主表 ...

  3. 10.27 noip模拟试题

    1.铺瓷砖(tile.cpp/c/pas)[问题描述]有一面很长很长的墙. 你需要在这面墙上贴上两行瓷砖. 你的手头有两种不同尺寸的瓷砖,你希望用这两种瓷砖各贴一行.瓷砖的长可以用分数表示,贴在第一行 ...

  4. [Redis] windows下安装 Redis

    一:Redis是什么? Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. 通过https://github.c ...

  5. U3D 通过预置对象实现手动创建精灵

    一: 这种可以在游戏的一开始,不显示某些物体,而且通过某种时机,来显示所需要显示的物体 这里就用到了实例化预置对象. 实例化更多通常用于实例投射物(如子弹.榴弹.破片.飞行的铁球等),AI敌人,粒子爆 ...

  6. 【转】 OC基础数据类型-NSSet

    原文 : http://www.cnblogs.com/GISerYang/p/3340937.html 1.集合:集合(NSSet)和数组(NSArray)有相似之处,都是存储不同的对象的地址:不过 ...

  7. OC - 27.CATransition

    概述 简介 CATransition又称转场动画,是CAAnimation的子类,可以直接使用 转场动画主要用于为图层提供移入/移出屏幕的动画效果 转场动画常见的应用是UINavigationCont ...

  8. Jmeter软件测试1--webservice测试

    写在前言 程序猿一枚,原本就是负责安安静静的撸代码,后来公司让兼任下测试的工作,还得照顾下面的几个测试兄弟,无奈本人毫无软件测试理论知识,下面的测试兄弟也是初级水平,又面临公司要求做webservic ...

  9. Problem 1183 - 排列

    #include<iostream> #include<vector> #include<algorithm> using namespace std; int c ...

  10. 解决linux .so的链接时符号依赖问题

    问题描述 target: a.out SO:libmyfile.so 依赖描述: a.out: libmyfile.so libmyfile.so:  libssl.so.1.0.0 libssl.s ...