結果

問題 No.425 ジャンケンの必勝法
ユーザー airisairis
提出日時 2016-09-23 00:44:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 996 bytes
コンパイル時間 3,782 ms
コンパイル使用メモリ 143,620 KB
実行使用メモリ 13,236 KB
最終ジャッジ日時 2023-08-11 06:00:46
合計ジャッジ時間 4,029 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 3 ms
6,000 KB
testcase_02 AC 2 ms
5,964 KB
testcase_03 AC 3 ms
6,244 KB
testcase_04 AC 6 ms
10,736 KB
testcase_05 AC 3 ms
10,388 KB
testcase_06 AC 5 ms
10,632 KB
testcase_07 AC 6 ms
10,912 KB
testcase_08 AC 4 ms
8,072 KB
testcase_09 AC 3 ms
8,248 KB
testcase_10 AC 3 ms
6,080 KB
testcase_11 AC 20 ms
13,152 KB
testcase_12 AC 19 ms
13,000 KB
testcase_13 AC 20 ms
13,172 KB
testcase_14 AC 20 ms
13,112 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
6,044 KB
testcase_17 AC 20 ms
13,236 KB
testcase_18 AC 3 ms
6,308 KB
testcase_19 AC 3 ms
6,240 KB
testcase_20 AC 20 ms
13,124 KB
testcase_21 AC 3 ms
5,892 KB
testcase_22 AC 3 ms
6,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

int p, q;
char done[105][10005];
double dp[105][10005];

double dfs(int r, int depth) {
	if (depth < 0) {
		return 0;
	}
	if (done[r][depth]) {
		return dp[r][depth];
	}

	double a, b;
	double pp = r / 100.0;

	// use
	a = pp / 2.0 + pp / 2 * dfs(max(0, r - q), depth - 1);
	// not use
	b = (1.0 - pp) / 3.0 + (1.0 - pp) / 3.0 * dfs(min(100, r + q), depth - 1);

	done[r][depth] = 1;
	return dp[r][depth] = a + b;
}

void solve() {
	printf("%.12f\n", 1.0 / 3.0 + 1.0 / 3.0 * dfs(p, 10000));
}

int main() {
	cin >> p >> q;
	solve();
	return 0;
}


0