結果

問題 No.425 ジャンケンの必勝法
ユーザー tubo28tubo28
提出日時 2016-09-22 23:49:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 997 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 163,728 KB
実行使用メモリ 341,168 KB
最終ジャッジ日時 2023-08-11 05:55:18
合計ジャッジ時間 13,432 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 228 ms
341,168 KB
testcase_01 AC 217 ms
341,024 KB
testcase_02 AC 224 ms
340,912 KB
testcase_03 AC 229 ms
341,088 KB
testcase_04 AC 296 ms
340,940 KB
testcase_05 AC 247 ms
340,912 KB
testcase_06 AC 252 ms
340,932 KB
testcase_07 AC 262 ms
341,116 KB
testcase_08 AC 217 ms
341,112 KB
testcase_09 AC 212 ms
341,112 KB
testcase_10 AC 204 ms
340,916 KB
testcase_11 AC 990 ms
341,144 KB
testcase_12 AC 995 ms
340,912 KB
testcase_13 AC 985 ms
341,048 KB
testcase_14 AC 988 ms
340,948 KB
testcase_15 AC 204 ms
341,112 KB
testcase_16 AC 222 ms
340,920 KB
testcase_17 AC 992 ms
340,916 KB
testcase_18 AC 213 ms
340,944 KB
testcase_19 AC 210 ms
340,912 KB
testcase_20 AC 997 ms
340,936 KB
testcase_21 AC 204 ms
340,916 KB
testcase_22 AC 203 ms
341,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int p0, q;

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