結果

問題 No.425 ジャンケンの必勝法
ユーザー femtofemto
提出日時 2016-09-22 23:01:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 80,216 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-11-17 19:28:27
合計ジャッジ時間 1,839 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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