洛谷 - three-divide-2

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

洛谷 - three-divide-2

three-divide-2.cpp

// Author : ysh
// 2025/09/17 Wed 14:03:34
// https://www.luogu.com.cn/problem/P3382
#include<bits/stdc++.h>
using namespace std;
#include<slow>
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;

    f.pop_back();
    reverse(all(f));
    re(i, n) f[i] = f[i] * (i + 1);

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

    #define check(i) ((get(i) > 0))
    function<long double(long double, long double)> ck = [&] (long double l, long double r) {
        if(abs(r - l) <= 1e-6) return l;
        long double mid = (l + r) / 2;

        if(check(mid)) return ck(mid, r);
        return ck(l, mid);
    };

    out(fixed);
    out(setprecision(10));
    out(ck(l, r));
    return 0;
}

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