結果

問題 No.425 ジャンケンの必勝法
ユーザー d2verbd2verb
提出日時 2017-09-13 02:17:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 900 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 163,576 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 07:16:51
合計ジャッジ時間 2,604 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,248 KB
testcase_01 AC 11 ms
5,376 KB
testcase_02 AC 11 ms
5,376 KB
testcase_03 AC 11 ms
5,376 KB
testcase_04 AC 11 ms
5,376 KB
testcase_05 AC 11 ms
5,376 KB
testcase_06 AC 11 ms
5,376 KB
testcase_07 AC 11 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 11 ms
5,376 KB
testcase_11 AC 11 ms
5,376 KB
testcase_12 AC 11 ms
5,376 KB
testcase_13 AC 11 ms
5,376 KB
testcase_14 AC 11 ms
5,376 KB
testcase_15 AC 11 ms
5,376 KB
testcase_16 AC 11 ms
5,376 KB
testcase_17 AC 11 ms
5,376 KB
testcase_18 AC 11 ms
5,376 KB
testcase_19 AC 11 ms
5,376 KB
testcase_20 AC 11 ms
5,376 KB
testcase_21 AC 11 ms
5,376 KB
testcase_22 AC 11 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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