题目链接: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): 4513    Accepted Submission(s):
1819

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
 
题目大意:生日聚会上,来到的所有朋友都会领取一块饼,但是要求的是所有人都要拿到大小相同的饼!题目要求输出的是:每个人尽量拿到的最大的饼的体积是多大。这里的饼的形状是高为1的圆柱形。V=底面积*高
特别注意:1、题目里要给你自己留一块。
     2、每个人得到的饼不可以是两块饼拼接在一起的。
     3、这里的PI要用acos(-1.0),具体原因还不知道为什么,可能精度要求比较高,因为这里wa几次。0.0
 
详见代码。
 #include <iostream>
#include <cstdio>
#include <cmath> using namespace std; #define PI acos(-1.0) int main ()
{
int t;
while (~scanf("%d",&t))
{
while (t--)
{
int n,f,r;
double V[],v=,vmax;
scanf("%d%d",&n,&f);
f=f+;
for (int i=; i<n; i++)
{
scanf("%d",&r);
V[i]=r*r*PI;
v+=V[i];
//cout<<v<<endl;
}
vmax=v/f;
double left,right,mid;
left=;
right=vmax;
int ans;
while ((right-left)>1e-)
{
int flag=,k=;
ans=;
mid=(left+right)/;
for (int i=;i<n;i++)
{
// ans+=(int)(V[i]/mid);
//if (ans>=f)
//flag=1;
double vv=V[i];
while(vv>=mid)
{
vv-=mid;
k++;
//cout<<vv<<" "<<k<<endl;
if(k==f)
{
flag=;
break;
}
}
if(flag==) break;
}
if(flag==)
left=mid;
else
right=mid;
}
printf("%.4lf\n",mid);
}
}
return ;
}

另外一种

 #include <iostream>
#include <cstdio>
#include <cmath> using namespace std; #define PI acos(-1.0) int main ()
{
int t;
while (~scanf("%d",&t))
{
while (t--)
{
int n,f,r;
double V[],v=,vmax;
scanf("%d%d",&n,&f);
f=f+;
for (int i=; i<n; i++)
{
scanf("%d",&r);
V[i]=r*r*PI;
v+=V[i];
//cout<<v<<endl;
}
vmax=v/f;
double left,right,mid;
left=;
right=vmax;
int ans;
while ((right-left)>1e-)
{
int flag=,k=;
ans=;
mid=(left+right)/;
for (int i=;i<n;i++)
{
ans+=(int)(V[i]/mid);
if (ans>=f)
flag=;
if(flag==) break;
}
if(flag==)
left=mid;
else
right=mid;
}
printf("%.4lf\n",mid);
}
}
return ;
}

hdu 1969 Pie(二分查找)的更多相关文章

  1. HDU 1969 Pie(二分查找)

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

  2. (step4.1.2)hdu 1969(Pie——二分查找)

    题目大意:n块馅饼分给m+1个人,每个人的馅饼必须是整块的,不能拼接,求最大的. 解题思路: 1)用总饼的体积除以总人数,得到每个人最大可以得到的V.但是每个人手中不能有两片或多片拼成的一块饼. 代码 ...

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

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

  4. HDU 1969 Pie [二分]

    1.题意:一项分圆饼的任务,一堆圆饼共有N个,半径不同,厚度一样,要分给F+1个人.要求每个人分的一样多,圆饼允许切但是不允许拼接,也就是每个人拿到的最多是一个完整饼,或者一个被切掉一部分的饼,要求你 ...

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

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

  6. 【hoj】2651 pie 二分查找

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

  7. Can you find it? HDU - 2141 (二分查找)

    Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...

  8. HDU 1969 Pie【二分】

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

  9. hdu 1969 pie 卡精度的二分

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

随机推荐

  1. BAT批处理(六)

    字符串处理 批处理有着具有非常强大的字符串处理能力,其功能绝不低于C语言里面的字符串函数集.批处理中可实现的字符串处理功能有:截取字符串内容.替换字符串特定字段.合并字符串.扩充字符串等功能.下面对这 ...

  2. ubuntu 安装lua错误

    转自:http://www.cnblogs.com/softidea/archive/2016/03/02/5236498.html lua.c:80:31: fatal error: readlin ...

  3. Jekyll 使用 Rouge 主题

    今日发现我的 Github Pages 中的代码并没有高亮,看了一下代码发现,原来的没有设置 css 样式的原因,我使用的代码高亮器是 rouge highlighter: rouge Rouge 是 ...

  4. Linux中实现在系统启动时自动加载模块

    下面是以前学习Linux时写的,后来仔细研究rc.sysinit后发现,只需要修改下列地方就可以了,不必这么麻烦的: rc.sysinit中有这样的一段代码: # Load other user-de ...

  5. jCanvaScript canvas的操作库

    在jcscript.com上下载最新的jCanvaScript.1.5.18.min.js文件  里面有很多关于canvas的方法都已经是封装好了的,只需直接调用,但是要注意调用之前和调用之后都要写: ...

  6. RT-thread v2.1.0修正版

    RT-Thread v2.1.0是v2.0.1正式版这个系列的bug修正版.RT-Thread v2.1.0修正的主要内容包括: 这个版本经历的时间比较长,并且原定的一些目标也还未能完成(更全的POS ...

  7. 【codevs3160】最长公共子串 后缀数组

    题目描述 给出两个由小写字母组成的字符串,求它们的最长公共子串的长度. 输入 读入两个字符串 输出 输出最长公共子串的长度 样例输入 yeshowmuchiloveyoumydearmotherrea ...

  8. Andorid API Package ---> android

    包名: android                                                        Added in API level 1  URL:http:// ...

  9. [洛谷P4999]烦人的数学作业

    题目大意:定义$f(x)$表示$x$每一个数位(十进制)的数之和,求$\sum\limits_{i=l}^rf(i)$,多组询问. 题解:数位$DP$,可以求出每个数字的出现个数,再乘上每个数字的大小 ...

  10. SPOJ1825/FTOUR2:Free tour II——包看得懂/看不懂题解

    http://www.spoj.com/problems/FTOUR2/en/ 题目大意:给一棵黑白染色的树,求边权和最大且经过黑点不超过K的路径. ———————————————————— 前排膜拜 ...