洛谷 - three-divide

本文最後更新於:2025年9月17日 下午

洛谷 - three-divide

three-divide.cpp

// Author : ysh
// 2025/09/17 Wed 13:33:48
// https://www.luogu.com.cn/problem/P3382
#include<bits/stdc++.h>
using namespace std;
#include<slow>
const int L = -18;
const int R = 5;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;long double l, r;cin>>n>>l>>r;
    vc<long double>f(n + 1);
    cin>>f;

    auto get = [&] (long double x) {
        long double now = 0;
        repo(&i, f) now = (now * x) + i;
        return now;
    };

    auto get_bit = [] (int x) {
        if(x >= 0) return (long double) (1 << x);
        else return ((long double) 1) / (1 << -x);
    };

    long double now = l;
    const long double low = get_bit(L);
    for(long double mask = (long double) (1ULL << R); mask >= low; mask = mask / 2) {
        if(now + mask > r) goto skip;
        debug(now, mask, get(now));
        if(get(now + mask) > get(now)) now = now + mask;

        skip:
        if(now - mask < l) continue;
        if(get(now - mask) > get(now)) now = now - mask;
    }

    out(fixed);
    out(setprecision(50));
    out(now);
    return 0;
}

洛谷 - three-divide
http://mysh212.github.io/algosolution/three-divide.cpp/
作者
ysh
發布於
2025年9月17日
更新於
2025年9月17日
許可協議