【分析】

“虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2。对于一个中值x和一张半径r的饼来说,这张饼能够分出的最多分数显然是:⌊π∗r2x⌋,所以我们只需要求出∑ni=1⌊π∗ri2x⌋,判断其与f+1的关系即可

特别要注意的一点:π的大小!,因为r≤104r≤104,所以r2≤108r2≤108,又因为题目要求精确到三位小数,所以ππ就要精确到10-11,即π=3.14159265358

Pie

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
 
Source
 
Recommend
wangye   |   We have carefully selected several similar problems for you:  1551 2899 2446 2298 2333 
 
【题意】:有n个饼,半径为ri(ri≤104ri≤104),分给m+1个人,要求每个人分到的面积是一样的,而且每个人分到的饼是连续的一块(即不能是几个小块凑起来的),求能够分到的最大面积,精确到三位小数
 
【代码】:

#include<bits/stdc++.h>
using namespace std;
#define Lint long long int
#define pi acos(-1)
const double eps=1e-;
const int MAXN=;
double r[MAXN],s[MAXN];
double n,L,R;
int T,m;
bool check(double mid)
{
int ret=;
for(int i=;i<=n;i++)
ret+=(int)(s[i]/mid);
return ret>=m; //一旦出现Pie的数目大于等于到场人数的话就true
}
int main()
{
scanf("%d",&T);
while( T-- )
{
L=R=;
scanf("%lf%d",&n,&m),m++;
//m的原来数值只是朋友的个数,而主人公也是一员,所以加1,加上主人公
for(int i=;i<=n;i++)
{
scanf("%lf",&r[i]);
s[i]=pi*r[i]*r[i]; //这里是直接把所输入的半径变量变成面积,方便下面计算
R+=s[i]; // 上界 也可以写成R=max(R,r[i]);这里是吧右边界给设成pie里面的最大的那一个
}
while( R-L>eps )
{
double mid=(L+R)/;
if( check( mid ) )
//如果返回值为真,那么代表我们可以用此时mid的大小来替换左边界,看是否存在比mid还大但仍然满足所有人都能吃到一样大小的pie,因为题目上说的是尽可能大
L=mid;
else
//一旦发现不符合的话,此时mid的大小就得替换掉右边界,继续在比mid小的大小里面找符合题目条件的大小
R=mid;
}
//最后输出l,因为只有满足条件的时候L的值才变,所以对于L来说,它是永远符合题目条件的那个值
printf("%.4lf\n",L);
}
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. HDU 1969 Pie(二分,注意精度)

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

  3. HDU 1969 Pie [二分]

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

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

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

  5. hdu 1969 Pie(二分查找)

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

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

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

  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(二分法)

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

  9. HDU 1969 精度二分

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

随机推荐

  1. The Best Path HDU - 5883 欧拉通路

    图(无向图或有向图)中恰好通过所有边一次且经过所有顶点的的通路成为欧拉通路,图中恰好通过所有边一次且经过所有顶点的回路称为欧拉回路,具有欧拉回路的图称为欧拉图,具有欧拉通路而无欧拉回路的图称为半欧拉图 ...

  2. linux学习-CentOS 7 环境下大量建置账号的方法

    一些账号相关的检查工具 pwck pwck 这个指令在检查 /etc/passwd 这个账号配置文件内的信息,与实际的家目录是否存在等信息, 还可以比对 /etc/passwd /etc/shadow ...

  3. foreach遍历数组的表格

    <?php /** * * @authors Your Name (you@example.org) * @date 2017-03-17 19:06:19 * @version $Id$ */ ...

  4. BZOJ 4369: [IOI2015]teams分组

    把一个人看成二维平面上的一个点,把一个K[i]看成左上角为(0,+max),右下角为(K[i],K[i])的一个矩阵,那么可以很好地描述人对于询问是否合法(我也不知道他怎么想到这东西的) 然后把一组询 ...

  5. UVa 465 Overflow——WA

    上次那个大数开方的高精度的题,UVa113 Power of Cryptography,直接两个double变量,然后pow(x, 1 / n)就A过去了. 怎么感觉UVa上高精度的题测试数据不给力啊 ...

  6. 深入理解Java虚拟机(精华总结)

    作者:战斗民族就是干 转自:http://www.cnblogs.com/prayers/p/5515245.html 一.运行时数据区域 Java虚拟机管理的内存包括几个运行时数据内存:方法区.虚拟 ...

  7. CRM知识点汇总(未完💩💩💩💩💩)

    一:项目中每个类的作用 StarkSite 对照admin中的AdminSite,相当于一个容器,用来存放类与类之间的关系. 先实例化对象,然后执行该对象的register方法.将注册类添加到_reg ...

  8. 基于UDP的交互的实例

    1.实现简单的客户端.服务端聊天交互 问题是:客户端不能单独一直发消息回复.. 服务端: import socket server=socket.socket(socket.AF_INET,socke ...

  9. 用Navicat Premium快速查看mysql数据库版本信息

    在出现的界面输入命令  select version();

  10. Welcome-to-Swift-03字符串和字符(Strings and Characters)

    String是例如“hello, world“”,“海贼王” 这样的有序的Character(字符)类型的值的集合,通过String类型来表示. Swift 的String和Character类型提供 ...