[CF77B] Falling Anvils

[CF77B] Falling Anvils - 概率

Description

给定 a,b,求 xx+sqrt(p)x+q 至少有一个实根的概率,p 属于 [0,a],q 属于 [-b,b],均为实数

Solution

算面积,分情况讨论即可

#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main()
{
    ios::sync_with_stdio(false);

    int t;
    cin >> t;
    while (t--)
    {
        double a, b;
        cin >> a >> b;

        double ans = 0;
        if (b == 0)
            ans = 1;
        else if (4 * b < a)
            ans = 1 - b / a;
        else
            ans = 0.5 + a / b / 16;
        cout << fixed << setprecision(16) << ans << endl;
    }
}
原文地址:https://www.cnblogs.com/mollnn/p/14420396.html