Pie

链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/C

题目:

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

题意:

有n个馅饼,有f个朋友,接下来是n个馅饼的半径。然后是分馅饼,
要求大家都要一样大,形状没什么要求,但都要是一整块的那种,也就说不能从两个饼中
各割一小块来凑一块。
题目要求我们分到的饼尽可能的大。 分析:
用二分法查找,
把0设为l,把y设为r。mid=(l+r)/2;
以mid为标志,如果所有的饼可以分割出f+1《还有自己》个mid,那么返回1,说明每个人可以得到的饼的体积可以
大于等于mid;如果不能分出这么多的mid,那么返回0,说明每个人可以得到饼的体积小于mid。
 注意精度
 代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
double pi=acos(-1.0); //用反余弦求pi
const int maxn=;
double sum,y;
int n,a[maxn],f;
double b[maxn];
int xz(double m)
{
int x=,i;
for(i=;i<n;i++)
{
x+=(int)(b[i]/m);
}
if(x>=f+)
return ;
else return ;
}
22 void slove()
{
double l=0.0,r=y,mid=;
while((r-l)>1e-) //精度问题
{
mid=(l+r)/;
if(xz(mid)) l=mid;
else r=mid;
}
printf("%.4f\n",l);
}
int main()
{
int i,t;
cin>>t;
while(t--)
{
sum=0.0;
cin>>n>>f;
for(i=;i<n;i++)
{
cin>>a[i];
b[i]=a[i]*a[i]*pi;
sum+=b[i];
}
y=sum/(f+);
slove();
}
return ;
}

 

分馅饼 Pie的更多相关文章

  1. hdu1969Pie(根据体积二分,分馅饼)

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

  2. [SinGuLaRiTy] 分治题目复习

    [SInGuLaRiTy-1025] Copyrights (c) SinGuLaRiTy 2017. All Rights Reserved. [POJ 1905] 棍的膨胀 (Expanding ...

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

  4. ACM pie

    我的生日快到了,传统上我正在做馅饼.不只是一个馅饼,不,我有N个,各种口味和各种尺寸. 数量为F我的朋友会来到我的聚会,每个人都得到一个馅饼. 这应该是一块馅饼,而不是几个小块,因为看起来很乱.这一块 ...

  5. poj3122--二分加贪心

    大致题意: 就是公平地分披萨pie 我生日,买了n个pie,找来f个朋友,那么总人数共f+1人 每个pie都是高为1的圆柱体,输入这n个pie的每一个尺寸(半径),如果要公平地把pie分给每一个人(就 ...

  6. POJ 3122 Pie(二分+贪心)

    Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22684   Accepted: 7121   Special Ju ...

  7. HDU1969 Pie(二分搜索)

    题目大意是要办生日Party,有n个馅饼,有f个朋友.接下来是n个馅饼的半径.然后是分馅饼了, 注意咯自己也要,大家都要一样大,形状没什么要求,但都要是一整块的那种,也就是说不能从两个饼中 各割一小块 ...

  8. POJ3122Pie(二分)

    http://poj.org/problem?id=3122 题意 :这个题最主要的就是审题要仔细,翻译不要漏句子.题目讲的是我要过生日,要给好友分馅饼(还有自己也想要一块),怕引起不公,所以每个人大 ...

  9. Android系统概述

    一.Android的诞生 Android这一词最先出现在法国作家利尔亚当在1886年发表的科幻小说<未来夏娃>中,作者将外表像人类的机器起名为Android,这也就是Android小人名字 ...

随机推荐

  1. AgileEAS.NET SOA 中间件2013第四季度发布&部分功能开源预告

    一.前言 AgileEAS.NET SOA 中间件平台是一款基于基于敏捷并行开发思想和Microsoft .Net构件(组件)开发技术而构建的一个快速开发应用平台.用于帮助中小型软件企业建立一条适合市 ...

  2. hdu 4293 2012成都赛区网络赛 dp ****

    题意:有n个人,可任意分成若干组,然后每个人个各提供一个信息,表示他们组前面有多少人,后面有多少人.问最多有多少个信息是不冲突的. 将n个人看成一组区间,然后每个人的信息可以表示为该人所在组的区间,然 ...

  3. Android三种基本的加载网络图片方式(转)

    Android三种基本的加载网络图片方式,包括普通加载网络方式.用ImageLoader加载图片.用Volley加载图片. 1. [代码]普通加载网络方式 ? 1 2 3 4 5 6 7 8 9 10 ...

  4. codeforces724-B. Batch Sort

    想着想着就忘了有什么问题没解决,坑啊 一开始读错题意了,而且一着急写了两大段差不多的代码,冗余度啊,不说了.. 显然的一点,给的数据是绝对离散的,每行都是1~m的排列 难点一.如何移动能使未排序的数组 ...

  5. Jmeter之csv、用户自定义变量以及Query Type分析(八)

    很多童鞋不知道对于Jmeter的Query Type 不知道选哪个,为什么选,怎么选! 下面这边做个简单的分析, 那么首先什么是CSV Data Set Config,有什么用呢? CSV Data ...

  6. fprintf, fscanf,printf,scanf使用时参数注意

    在利用fprintf函数将数据按格式输出到文件中时,通常需要限定数据的格式,例如: FILE *f=fopen("d:\\1.txt","w+"); int a ...

  7. Portlet简述

    一.Portlet是什么? Portlet是基于java的web组件,由portlet容器管理,并由容器处理请求,生产动态内容.Portals使用portlets作为可插拔用户接口组件,提供信息系统的 ...

  8. HTML meta viewport属性说明(mark)

    什么是Viewport 手机浏览器是把页面放在一个虚拟的“窗口”(viewport)中,通常这个虚拟的“窗口”(viewport)比屏幕宽,这样就不用把每个网页挤 到很小的窗口中(这样会破坏没有针对手 ...

  9. 改变图片尺寸(python)

    for name in /图片路径; do convert -resize 256x256! $name $namedone

  10. String的一些总结(JAVA)

    equals: String s1=new String("Hello"); String s2=new String("Hello"); System.out ...