結果

問題 No.425 ジャンケンの必勝法
ユーザー d2verb
提出日時 2017-09-13 02:17:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 900 bytes
コンパイル時間 1,597 ms
コンパイル使用メモリ 166,468 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-07 17:33:18
合計ジャッジ時間 2,700 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

double solve(double p, double q, int d) {
  if (d > 20)
    return 1;

  double pp = 0.0;
  
  // use strategy
  pp += p / 2.0;
  pp += p / 2.0 * solve(max(0.0, p - q), q, d + 1);

  // not use strategy
  pp += (1.0 - p) / 3.0;
  pp += (1.0 - p) / 3.0 * solve(min(1.0, p + q), q, d + 1);

  return pp;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  double p, q;
  cin >> p >> q;

  p /= 100.0;
  q /= 100.0;

  double ans = 1.0 / 3.0 + solve(p, q, 0) / 3.0;
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}
0