【題解】ZeroJudge e510: 10056 – What is the Probability?

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=e510
【解題想法】機率的數值解

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int S, N, K;
    double p;
    cin >> S;
    while (S--){
        cin >> N >> p >> K;
        if (p == 0) {
            cout << "0.0000\n";
            continue;
        }
        double first = pow(1.0 - p, K-1) * p;
        double r = pow(1.0 - p, N);
        cout << fixed << setprecision(4) <<
        first / (1.0 - r) << "\n";
    }
    return 0;
}
分享本文 Share with friends