結果

問題 No.173 カードゲーム(Medium)
ユーザー kenkooookenkoooo
提出日時 2015-03-27 00:55:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,192 ms / 3,000 ms
コード長 1,534 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 75,936 KB
実行使用メモリ 70,960 KB
最終ジャッジ日時 2023-09-11 10:40:42
合計ジャッジ時間 12,059 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 235 ms
60,996 KB
testcase_01 AC 337 ms
63,168 KB
testcase_02 AC 1,192 ms
70,960 KB
testcase_03 AC 1,168 ms
70,480 KB
testcase_04 AC 906 ms
68,892 KB
testcase_05 AC 894 ms
68,228 KB
testcase_06 AC 983 ms
69,616 KB
testcase_07 AC 934 ms
69,572 KB
testcase_08 AC 775 ms
70,036 KB
testcase_09 AC 889 ms
69,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Random random = new Random();
		int N = sc.nextInt();
		double Pa = sc.nextDouble();
		double Pb = sc.nextDouble();

		int[] a = new int[N];
		int[] b = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			b[i] = sc.nextInt();
		}
		sc.close();

		int rep = 100000;

		int wina = 0;
		for (int i = 0; i < rep; i++) {
			int pointa = 0;
			int pointb = 0;

			ArrayList<Integer> aList = new ArrayList<>();
			ArrayList<Integer> bList = new ArrayList<>();
			for (int j = 0; j < N; j++) {
				aList.add(a[j]);
				bList.add(b[j]);
			}
			Collections.sort(aList);
			Collections.sort(bList);
			for (int j = 0; j < N; j++) {
				double rand_a = random.nextDouble();
				double rand_b = random.nextDouble();

				int card_aid = (rand_a < Pa || aList.size() == 1) ? 0 : random.nextInt(aList.size() - 1) + 1;
				int card_bid = (rand_b < Pb || bList.size() == 1) ? 0 : random.nextInt(bList.size() - 1) + 1;
				int card_a = aList.get(card_aid);
				aList.remove(card_aid);
				int card_b = bList.get(card_bid);
				bList.remove(card_bid);

				if (card_a > card_b) {
					pointa += card_a + card_b;
				} else if (card_a < card_b) {
					pointb += card_a + card_b;
				}
			}
			if (pointa > pointb) {
				wina++;
			}
		}
		System.out.println((double) wina / rep);

	}
}
0