結果

問題 No.425 ジャンケンの必勝法
ユーザー tubo28tubo28
提出日時 2016-09-22 23:53:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 167,848 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 22:42:17
合計ジャッジ時間 2,300 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int p0, q;

const int LIM = 19;
ld dp[101][LIM+1];

ld f(int p, int r) {
    ld &res = dp[p][r];
    if (res >= -1) return res;

    res = 0;
    if(r < LIM){
        ld p_ = p / 100.0;
        res += p_     * (1.0/2) * f(max(0,   p-q), r+1); // d
        res += p_     * (1.0/2) * 1; // w
        res += (1-p_) * (1.0/3) * 0; // l
        res += (1-p_) * (1.0/3) * f(min(100, p+q), r+1); // d
        res += (1-p_) * (1.0/3) * 1; // w
    }
    return res;
}

int main() {
    while (cin >> p0 >> q) {
        fill((ld*)begin(dp), (ld*)end(dp), -10);
        ld ans = (f(p0,0)+1) / 3;
        printf("%.10lf\n", (double)ans);
    }
}
0