結果

問題 No.425 ジャンケンの必勝法
ユーザー tomerun
提出日時 2016-09-22 22:48:15
言語 Java
(openjdk 23)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 2,334 ms
コンパイル使用メモリ 77,272 KB
実行使用メモリ 41,528 KB
最終ジャッジ日時 2024-11-17 19:07:47
合計ジャッジ時間 10,516 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int P = sc.nextInt();
		int Q = sc.nextInt();
		double[][] dp = new double[2][101];
		double ans = 1.0 / 3;
		dp[0][P] = 1.0 / 3;
		int t = 0;
		for (int i = 0; i < 100000; ++i) {
			Arrays.fill(dp[1 - t], 0);
			for (int j = 0; j <= 100; ++j) {
				// use
				ans += 0.01 * j * dp[t][j] / 2;
				dp[1 - t][Math.max(0, j - Q)] += 0.01 * j * dp[t][j] / 2;

				// not use
				ans += 0.01 * (100 - j) * dp[t][j] / 3;
				dp[1 - t][Math.min(100, j + Q)] += 0.01 * (100 - j) * dp[t][j] / 3;
			}
			t = 1 - t;
		}
		System.out.printf("%.9f\n", ans);
	}
}
0