HDU_1969_Pie

这个题目基本就是坑细节和精度。

是否求饼的总面积然后除以人数来确定二分上限并不是这个问题的关键。

而且不知道饼多的时候求总面积会不会产生误差。

另外收到提醒 count,max等最好不再作为变量。

#include <iostream>
#include<stdio.h>
#include<cmath>

using namespace std;

typedef double LD;
const LD AC=1e-6;  //保留4位要多一些,但太高会超时
const LD PI=acos(-1.0);

const int M=10005;
LD r[M];

int npi(LD x,int n)
{
    int count=0;
    for(int i=0;i<n;i++)
        count+=floor(r[i]/x);  //这里要向下取正
    return count;
}

LD bs(LD max,int f,int n)
{

    LD lo=0,hi=max;
    LD mid;
    while(hi-lo>=AC)
    {
        mid=(hi+lo)/2.0;
        if(npi(mid,n)>=f)
            lo=mid;
        else
            hi=mid;
    }
    return lo;                //lo是最满足题目条件的hi与mid不一定
}

int main()
{
    int t;
    int n,f;
    LD maxp;
    scanf("%d",&t);
    while(t--)
    {
        maxp=0;
        scanf("%d%d",&n,&f);
        f++;           //把f从朋友数变成总人数
        for(int i=0;i<n;i++)
        {
            scanf("%lf",&r[i]);
            r[i]=r[i]*r[i]*PI;
            if(r[i]>maxp)
                maxp=r[i];
        }

        printf("%.4lf\n",bs(maxp,f,n));  //这里是个坑,必须写%.4lf别的不行
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值