結果

問題 No.425 ジャンケンの必勝法
コンテスト
ユーザー olphe
提出日時 2016-09-23 00:06:51
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 880 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 202 ms
コンパイル使用メモリ 40,736 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-12 14:13:22
合計ジャッジ時間 1,224 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include "stdio.h"

double p,q;
double ans;


void sum(int fig,double now, int pre,double con) {
	if (fig > 20)return;
	if (pre== 1) {
		if (now - q > 0.0) {
			sum(fig + 1, now - q, 1, con/2.0*(now-q));
			sum(fig + 1, now-q, 0, con / 3.0*(1.0 - now + q));
			ans += con*((now - q) / 2.0 + (1.0 - now + q) / 3.0);
		}
		else {
			sum(fig + 1, 0.0, 0, con / 3.0);
			ans += con / 3.0;
		}
	}
	else {
		if (now + q < 1.0) {
			sum(fig + 1, now + q, 1, con / 2.0 * (now + q));
			sum(fig + 1, now + q, 0, con / 3.0 * (1.0 - now - q));
			ans += con*((now + q) / 2.0 + (1 - now - q) / 3.0);
		}
		else {
			sum(fig + 1, 1.0, 1, con / 2.0);
			ans += con / 2.0;
		}
	}
}


int main() {
	scanf("%lf %lf", &p, &q);
	p = p / 100;
	q = q / 100;
	ans += 1.0 / 3.0;
	ans += p / 6.0;
	ans += (1 - p) / 9.0;
	sum(1, p, 1, p / 6.0);
	sum(1, p, 0, (1-p)/9.0);
	printf("%f\n", ans);
	return 0;
}
0