結果

問題 No.425 ジャンケンの必勝法
ユーザー olpheolphe
提出日時 2016-09-23 00:06:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 880 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 26,436 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-11 05:57:42
合計ジャッジ時間 1,331 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#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