結果

問題 No.425 ジャンケンの必勝法
ユーザー uenokuuenoku
提出日時 2016-12-02 00:36:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,233 bytes
コンパイル時間 571 ms
コンパイル使用メモリ 74,408 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 11:55:52
合計ジャッジ時間 2,386 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> P;
lli MOD = 1000000007;
double f(double, int);
double g(double, int);
double p, q;
double r = 1.0 / 3.0;
double fdp[105] = {};
double gdp[105] = {};
double f(double x, int dph)
{
    int xx = (int)(x * 100);
    //if (fdp[xx] != 0)
    //return fdp[xx];
    double tp = min(1.0, x + q);
    if (dph == 0)
        return 0;
    return fdp[xx] = tp * 0.5 + tp * 0.5 * g(tp, dph - 1) + (1 - tp) * r + (1 - tp) * r * f(tp, dph - 1);
}
double g(double x, int dph)
{
    int xx = (int)(x * 100);
    //if (gdp[xx] != 0)
    //return gdp[xx];

    double tp = max(0.0, x - q);
    if (dph == 0)
        return 0;
    return gdp[xx] = tp * 0.5 + tp * 0.5 * g(tp, dph - 1) + (1 - tp) * r + (1 - tp) * r * f(tp, dph - 1);
}

int main()
{
    cin >> p >> q;
    p /= 100.0;
    q /= 100.0;
    double ans = 0;
    ans = r + r * (p * 0.5 + p * 0.5 * g(p, 20) + (1 - p) * r + (1 - p) * r * f(p, 20));
    printf("%.10f\n", ans);
}
0