結果

問題 No.425 ジャンケンの必勝法
ユーザー femtofemto
提出日時 2016-09-22 23:01:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 1,061 ms
コンパイル使用メモリ 79,456 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2023-08-11 05:45:56
合計ジャッジ時間 2,568 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,592 KB
testcase_01 AC 7 ms
6,696 KB
testcase_02 AC 6 ms
6,692 KB
testcase_03 AC 6 ms
6,612 KB
testcase_04 AC 7 ms
6,700 KB
testcase_05 AC 6 ms
6,540 KB
testcase_06 AC 6 ms
6,696 KB
testcase_07 AC 7 ms
6,696 KB
testcase_08 AC 6 ms
6,628 KB
testcase_09 AC 6 ms
6,780 KB
testcase_10 AC 7 ms
6,688 KB
testcase_11 AC 7 ms
6,536 KB
testcase_12 AC 7 ms
6,612 KB
testcase_13 AC 7 ms
6,684 KB
testcase_14 AC 7 ms
6,768 KB
testcase_15 AC 6 ms
6,692 KB
testcase_16 AC 6 ms
6,748 KB
testcase_17 AC 7 ms
6,784 KB
testcase_18 AC 7 ms
6,592 KB
testcase_19 AC 6 ms
6,700 KB
testcase_20 AC 7 ms
6,684 KB
testcase_21 AC 6 ms
6,604 KB
testcase_22 AC 6 ms
6,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;
typedef long double ld;
const int MAX = 1000;
ld dp[MAX + 10][101][2];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int p0, q;
	cin >> p0 >> q;

	ld ans = 1.0 / 3.0;

	dp[0][p0][0] = 1.0 / 3.0;
	for(int i = 0; i < MAX; i++) {
		for(int j = 0; j <= 100; j++) {
			for(int k = 0; k < 2; k++) {
				if(dp[i][j][k] == 0) continue;
				// use
				ans += j / 100.0 * dp[i][j][k] / 2;
				dp[i + 1][max(0, j - q)][1] += j / 100.0 * dp[i][j][k] / 2;
				// not use
				ans += (100 - j) / 100.0 * dp[i][j][k] / 3;
				dp[i + 1][min(100, j + q)][0] += (100 - j) / 100.0 * dp[i][j][k] / 3;
			}
		}
	}

	cout << setprecision(15) << ans << endl;
}
0