Pie UVA - 12097(浮点数 二分答案)

Pie UVA - 12097

题意:

有f+1个人要分N种圆形pai,每个人分到一整块pai(而不是几块拼在一起,且面积要相同,不必是圆形)。

每个人分到的pai应尽量大。

思路:

  1. 典型的二分答案。
  2. 这里注意二分时的LR浮点数

反思:(如下)

const double eps = 1e-5;
//
 while(R-L>eps){///L<R
   double mid=(R+L)/2;
    if(check(mid)) L = mid;
    else R = mid;
}

AC

#include <iostream>
#include <bits/stdc++.h>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
#define fori(i,x,y) for(int i=(x); i<(y); i++)
#define rep(i,y,x) for(int i=(y); i>=(x); i--)
#define mst(x,a) memset(x,a,sizeof(x))
#define pb push_back
#define sz(a) (int)a.size()
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pa;
typedef pair<ll,ll>pai;
const double eps = 1e-5;
const double PI = acos(-1.0);
const int maxn = 1e4+10;
double A[maxn];
int f, n;
bool check(double area){
    int res = 0;
    For(i,1,n)res += floor(A[i]/area);
    return res>=f+1;
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   // cout<<PI<<endl;
    int tt; scanf("%d", &tt);
    while(tt--){
        scanf("%d%d", &n, &f);
        double L = 0, R = 0;
        For(i,1,n){
            int r; scanf("%d", &r);
            A[i] = r*r*PI;
            R = max(R, A[i]);
        }
        while(R-L>eps){///L<R
            double mid=(R+L)/2;
            if(check(mid)) L = mid;
            else R = mid;
        }
        printf("%.4f\n", L);
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值