結果

問題 No.133 カードゲーム
ユーザー uafr_csuafr_cs
提出日時 2015-08-10 20:22:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 309 ms / 5,000 ms
コード長 1,242 bytes
コンパイル時間 2,491 ms
コンパイル使用メモリ 75,748 KB
実行使用メモリ 58,056 KB
最終ジャッジ日時 2023-09-07 09:21:22
合計ジャッジ時間 10,441 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 231 ms
56,496 KB
testcase_01 AC 234 ms
58,056 KB
testcase_02 AC 222 ms
55,864 KB
testcase_03 AC 170 ms
55,752 KB
testcase_04 AC 269 ms
56,516 KB
testcase_05 AC 306 ms
56,840 KB
testcase_06 AC 304 ms
56,220 KB
testcase_07 AC 309 ms
56,616 KB
testcase_08 AC 270 ms
55,952 KB
testcase_09 AC 268 ms
56,584 KB
testcase_10 AC 306 ms
56,348 KB
testcase_11 AC 307 ms
56,192 KB
testcase_12 AC 305 ms
56,128 KB
testcase_13 AC 230 ms
56,552 KB
testcase_14 AC 266 ms
56,648 KB
testcase_15 AC 267 ms
56,356 KB
testcase_16 AC 308 ms
56,752 KB
testcase_17 AC 300 ms
57,256 KB
testcase_18 AC 305 ms
56,248 KB
testcase_19 AC 307 ms
56,624 KB
testcase_20 AC 302 ms
56,312 KB
testcase_21 AC 304 ms
56,600 KB
testcase_22 AC 306 ms
56,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int[] AS = new int[N];
		final int[] BS = new int[N];
		
		for(int i = 0; i < N; i++){
			AS[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++){
			BS[i] = sc.nextInt();
		}
		
		ArrayList<Integer> A_random = new ArrayList<Integer>();
		ArrayList<Integer> B_random = new ArrayList<Integer>();
		for(int i = 0; i < N; i++){
			A_random.add(i);
			B_random.add(i);
		}
		
		double answer = Double.NaN;
		for(int i = 0; i < 1000000; i++){
			Collections.shuffle(A_random);
			Collections.shuffle(B_random);
			
			int count = 0;
			for(int j = 0; j < N; j++){
				count += (AS[A_random.get(j)] > BS[B_random.get(j)]) ? 1 : 0;
			}
			
			double prob = (count > N / 2) ? 1 : 0;
			
			if(Double.isNaN(answer)){
				answer = prob;
			}else{
				answer += (prob / i);
				answer *= i;
				answer /= (i + 1);
			}
			//System.out.printf("%d : %.08f\n", i, answer);
		}
		
		System.out.printf("%.08f\n", answer);
	}
	
}
0