leeing Sunlight Gym - 103061F

题目链接

在这里插入图片描述

超高精度二分

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

struct node
{
    double l, r, av;
} a[100010];

int main(int argc, char const *argv[])
{
    int n, m;
    double minn = 0x3f3f3f3f, maxx = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i].l >> a[i].r;
        if (a[i].l < minn)
            minn = a[i].l;
        if (a[i].r > maxx)
            maxx = a[i].r;
        a[i].av = a[i].r - a[i].l;
    }
    while (maxx - minn > 1e-5)
    {
        double mid = (minn + maxx) / 2;
        double sum = 0;
        for (int i = 0; i < n; i++)
            if (mid >= a[i].r)
                sum += 1.0;
            else if (mid > a[i].l && mid < a[i].r)
                sum += (mid - a[i].l) / a[i].av;
        if (sum >= m)//这里必须是>=不能是>,因为题目中要找的是最小的x使得炸鱼的期望>=m,如果我们找到了一个x使炸鱼的期望>=m就退出查找是不对的,因为得找最小的,所以哪怕找到了一个期望>=m我们也得继续二分找下去,直到maxx-minn<1e-5
            maxx = mid;
        else
            minn = mid;
    }
    printf("%.10f\n", maxx);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值