結果

問題 No.173 カードゲーム(Medium)
ユーザー kenkooookenkoooo
提出日時 2015-03-27 00:50:53
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,539 bytes
コンパイル時間 3,328 ms
コンパイル使用メモリ 82,196 KB
実行使用メモリ 70,472 KB
最終ジャッジ日時 2023-09-11 10:37:04
合計ジャッジ時間 9,104 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 222 ms
59,960 KB
testcase_01 AC 259 ms
59,588 KB
testcase_02 WA -
testcase_03 AC 699 ms
70,268 KB
testcase_04 AC 675 ms
68,904 KB
testcase_05 AC 595 ms
67,816 KB
testcase_06 AC 621 ms
67,624 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 690 ms
68,892 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() * 100;
		double Pb = sc.nextDouble() * 100;

		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 = 50000;

		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++) {
				int rand_a = random.nextInt(100);
				int rand_b = random.nextInt(100);

				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