题目链接: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. dev_queue_xmit 发生了什么?skb还会在哪里缓存

    见 codebox/net/qdisk/xmit.log中保存了一份记录 调用关系 sch_direct_xmit --> dev_hard_start_xmit --> xmit_one ...

  2. 安装多个版本JDK相关问题

    一.前言 因敝人计算器上面安装了多个版本的JDK,其中包括JDK1.6.JDK1.7.JDK1.8,想通过变换环境变量(JAVA_HOME)的形式切换不同的JDK,但是我在安装了JDK1.7并且配置了 ...

  3. Wannafly 挑战赛16 A 取石子

    题目描述 给出四堆石子,石子数分别为a,b,c,d.规定每次只能从堆顶取走石子,问取走所有石子的方案数. 输入描述: 在一行内读入四个由空格分隔的整数a,b,c,d, 输入均为不超过500的正整数 输 ...

  4. bzoj3864-hdu4899-Hero meet devil

    题目 给出一个由AGTC组成的字符串\(S\),长度为\(n\),对于每个\(i\in [0,n]\),问有多少个长度为\(m\),仅含有AGTC的字符串\(T\)使得\(S\)与\(T\)的最长公共 ...

  5. BZOJ5301:[CQOI2018]异或序列——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=5301 https://www.luogu.org/problemnew/show/P4462 已知 ...

  6. [Ahoi2005]COMMON 约数研究 【欧拉线性筛的应用】

    1968: [Ahoi2005]COMMON 约数研究 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 2939  Solved: 2169 [Submi ...

  7. 洛谷 P3644 [APIO2015]八邻旁之桥 解题报告

    P3644 [APIO2015]八邻旁之桥 题目描述 一条东西走向的穆西河将巴邻旁市一分为二,分割成了区域\(A\)和区域\(B\). 每一块区域沿着河岸都建了恰好\(1000000001\)栋的建筑 ...

  8. Mac将应用拖入Finder工具栏

    在Finder的工具栏上放一下应用,方便打开对应的文件,可以 Command + 鼠标拖动应用,将应用拖入Finder工具栏中. 本人的Finder工具栏上添加了vscode这个应用

  9. bzoj4870: [Shoi2017]组合数问题(DP+矩阵乘法优化)

    为了1A我居然写了个暴力对拍... 那个式子本质上是求nk个数里选j个数,且j%k==r的方案数. 所以把组合数的递推式写出来f[i][j]=f[i-1][j]+f[i-1][(j-1+k)%k].. ...

  10. 【树状数组】【P2345】 奶牛集会

    传送门 Description 约翰的\(N\)头奶牛每年都会参加"哞哞大会".哞哞大会是奶牛界的盛事.集会上的活动很多,比如堆干草,跨栅栏,摸牛仔的屁股等等.它们参加活动时会聚在 ...