結果

問題 No.425 ジャンケンの必勝法
ユーザー tubo28tubo28
提出日時 2016-09-22 23:50:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 731 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 167,288 KB
実行使用メモリ 88,148 KB
最終ジャッジ日時 2024-04-28 22:41:57
合計ジャッジ時間 4,970 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
87,936 KB
testcase_01 AC 61 ms
88,096 KB
testcase_02 AC 61 ms
87,988 KB
testcase_03 AC 64 ms
87,988 KB
testcase_04 AC 82 ms
87,960 KB
testcase_05 AC 64 ms
87,912 KB
testcase_06 AC 73 ms
88,116 KB
testcase_07 AC 76 ms
88,044 KB
testcase_08 AC 64 ms
88,104 KB
testcase_09 AC 64 ms
88,112 KB
testcase_10 AC 61 ms
88,020 KB
testcase_11 AC 260 ms
87,908 KB
testcase_12 AC 260 ms
88,100 KB
testcase_13 AC 262 ms
88,148 KB
testcase_14 AC 261 ms
87,924 KB
testcase_15 AC 61 ms
88,080 KB
testcase_16 AC 61 ms
88,068 KB
testcase_17 AC 263 ms
88,116 KB
testcase_18 AC 64 ms
88,080 KB
testcase_19 AC 63 ms
88,044 KB
testcase_20 AC 259 ms
88,120 KB
testcase_21 AC 61 ms
88,148 KB
testcase_22 AC 62 ms
87,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int p0, q;

const int LIM = 50000;
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