結果
| 問題 |
No.425 ジャンケンの必勝法
|
| コンテスト | |
| ユーザー |
airis
|
| 提出日時 | 2016-09-23 00:44:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 996 bytes |
| コンパイル時間 | 1,041 ms |
| コンパイル使用メモリ | 158,992 KB |
| 実行使用メモリ | 13,056 KB |
| 最終ジャッジ日時 | 2024-11-17 19:45:35 |
| 合計ジャッジ時間 | 1,803 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 18 |
ソースコード
#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;
}
airis