【Codeforces Round #185 (Div. 2) B】Archer

【链接】 链接
【题意】

在这里输入题意

【题解】

概率水题。 枚举它是第几轮成功的。 直到满足精度就好

【错的次数】

1

【反思】

long double最让人安心。

【代码】

#include <bits/stdc++.h>
#define double long double
#define ll long long
using namespace std;

double a,b,c,d;

int main()
{
    cin >> a >> b >> c >> d;
    double p1 = a/b,p2 = c/d;
    double temp = 1;
    double ans = 0;
    double preans = 0;
    for (int i = 1;;i++)
    {
        ans += temp*p1;
        if (i > 1 && abs(preans-ans) < (1e-9) ) break;
        temp*=(1-p1)*(1-p2);
        preans = ans;
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7634268.html