【UVA12097】Pie

题面

  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 com-plaining. 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.

题意

  有 n 个饼,半径为ri ri104 ),分给 f+1 个人,要求每个人分到的面积是一样的,而且每个人分到的饼是连续的一块(即不能是几个小块凑起来的),求能够分到的最大面积,精确到三位小数

解法

二分:
  虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲)
  考虑二分面积,下界 L=0 ,上界 R=ni=1πri2 。对于一个中值 x 和一张半径为r的饼来说,这张饼能够分出的最多分数显然是: πr2x ,所以我们只需要求出 ni=1πri2x ,判断其与 f+1 的关系即可
  特别要注意的一点:π的大小!!!,因为 r104 ,所以 r2108 ,又因为题目要求精确到三位小数,所以 π 就要精确到10-11,即π=3.14159265358

拓展

maze

分析

  maze代码:https://gitee.com/qjlyh/codes/dg3rbnm45xfz7ytjlckhu64
  maze数据:https://pan.baidu.com/s/1eS3Z9aq

复杂度

O(nlogRL

代码

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<queue>
#define Lint long long int
using namespace std;
const double pi=3.141592653589;//79323846
const double eps=1e-6;
const int MAXN=10010;
double r[MAXN],s[MAXN];
double n,L,R;
int T,f;
bool check(double lim)
{
    int ret=0;
    for(int i=1;i<=n;i++)
        ret+=(int)(s[i]/lim);
    return ret>=f;
}
int main()
{
    scanf("%d",&T);
    while( T-- )
    {
        L=R=0;
        scanf("%lf%d",&n,&f),f++;
        for(int i=1;i<=n;i++)
        {
            scanf("%lf",&r[i]);
            s[i]=pi*r[i]*r[i];
            R+=s[i];
        }
        while( R-L>eps )
        {
            double mid=(L+R)/2;
            if( check( mid ) )   L=mid;
            else   R=mid;
        }
        printf("%.4lf\n",L);
    }
    return 0;
}
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值