結果

問題 No.58 イカサマなサイコロ
ユーザー YamaKasaYamaKasa
提出日時 2018-06-26 23:47:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 665 ms / 5,000 ms
コード長 726 bytes
コンパイル時間 3,978 ms
コンパイル使用メモリ 71,812 KB
実行使用メモリ 56,732 KB
最終ジャッジ日時 2023-09-13 14:16:01
合計ジャッジ時間 7,251 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 240 ms
55,608 KB
testcase_01 AC 665 ms
55,792 KB
testcase_02 AC 241 ms
56,444 KB
testcase_03 AC 192 ms
56,176 KB
testcase_04 AC 442 ms
55,868 KB
testcase_05 AC 502 ms
55,292 KB
testcase_06 AC 602 ms
56,416 KB
testcase_07 AC 244 ms
56,732 KB
testcase_08 AC 342 ms
56,212 KB
testcase_09 AC 609 ms
55,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		scan.close();
		int p1;			// 普通のサイコロの和
		int p2; 		// イカサマなサイコロの和
		int n = 1000000;	// シミュレーション回数
		int win = 0;	// p2の勝利数
		for(int i = 0; i < n; i++) {
			p1 = 0;
			p2 = 0;
			for(int j = 0; j < N; j++) {
				p1 += (int)(Math.random() * 6) + 1;
				if(j < K) {
					p2 += (int)(Math.random() * 3) + 4;
				}else {
					p2 += (int)(Math.random() * 6) + 1;
				}
			}
			if(p2 > p1) {
				win ++;
			}
		}
		double ans = (double) win / n;
		System.out.println(ans);
	}
}
0