結果

問題 No.425 ジャンケンの必勝法
ユーザー srup٩(๑`н´๑)۶
提出日時 2016-09-23 02:34:45
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 61,044 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-17 19:50:50
合計ジャッジ時間 1,460 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

double dfs(double c, double p, double q, int t){
	// printf("%f %f %f %d\n", c, p, q, t);
	if(t > 20){
		return 0.0;
	}
	double ret = 0.0;
	//必勝法を使って勝つ確率
	ret += (p * c * 0.5);
	//必勝法を使ってあいこになる確率
	ret += dfs(p * c * 0.5, max(0.0, p - q), q, t + 1);
	//必勝法を使わずに勝つ確率
	ret += ((1 - p) * c / 3.0);
	//必勝法を使わずに愛子になる確率
	ret += dfs((1 - p) * c / 3.0, min(1.0, p + q), q, t + 1);
	return ret;
}

int main(void){
	double p0, q;
    cin >> p0 >> q;
    printf("%.9f\n", dfs(1.0 / 3.0, p0 / 100.0, q / 100.0, 1) + 1.0 / 3.0);
    return 0;
}
0