結果

問題 No.425 ジャンケンの必勝法
ユーザー ふーらくたる
提出日時 2016-09-22 23:49:27
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 61,712 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-17 19:42:32
合計ジャッジ時間 1,239 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

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

double table[1000][101];
bool used[1000][101];

int p0, q;

double solve(int times, int p) {
    if (used[times][p]) {
        return table[times][p];
    }
    if (times == 200) {
        used[times][p] = true;
        return table[times][p] = 1.0 / 3.0;
    }
    used[times][p] = true;
    double res;
    if (times == 0) {
        res = 1 / 3.0 + 1 / 3.0 * (solve(times + 1, p));
    } else {
        res = (double)p / 100.0 * (0.5 + 0.5 * solve(times + 1, max(p - q, 0))) +
                        (double)(100 - p) / 100.0 * (1 / 3.0 + 1 / 3.0 * solve(times + 1, min(p + q, 100)));
    }
    return table[times][p] = res;
}

int main() {
    cin >> p0 >> q;
    cout << fixed << setprecision(10) << solve(0, p0) << endl;

    return 0;
}
0