結果

問題 No.133 カードゲーム
ユーザー kenji_shioyakenji_shioya
提出日時 2016-07-03 18:40:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 1,151 bytes
コンパイル時間 2,805 ms
コンパイル使用メモリ 74,888 KB
実行使用メモリ 56,556 KB
最終ジャッジ日時 2023-09-07 09:26:11
合計ジャッジ時間 6,185 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
55,720 KB
testcase_01 AC 106 ms
55,616 KB
testcase_02 AC 104 ms
55,912 KB
testcase_03 AC 102 ms
55,936 KB
testcase_04 AC 105 ms
55,976 KB
testcase_05 AC 115 ms
56,556 KB
testcase_06 AC 105 ms
56,288 KB
testcase_07 AC 105 ms
55,808 KB
testcase_08 AC 106 ms
55,892 KB
testcase_09 AC 108 ms
56,368 KB
testcase_10 AC 107 ms
55,728 KB
testcase_11 AC 104 ms
55,844 KB
testcase_12 AC 106 ms
56,036 KB
testcase_13 AC 107 ms
55,868 KB
testcase_14 AC 106 ms
55,920 KB
testcase_15 AC 103 ms
56,280 KB
testcase_16 AC 105 ms
55,900 KB
testcase_17 AC 120 ms
55,764 KB
testcase_18 AC 106 ms
55,712 KB
testcase_19 AC 104 ms
56,000 KB
testcase_20 AC 108 ms
56,128 KB
testcase_21 AC 106 ms
55,996 KB
testcase_22 AC 103 ms
54,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise143{
  public static double winGames;
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] a = new int[n];
    ArrayList<Integer> b = new ArrayList<Integer>();
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }
    for(int i = 0; i < n; i++){
      b.add(sc.nextInt());
    }
    double sumGames = 1;
    winGames = 0;

    for(int i = 0; i < n; i++){
      sumGames *= n - i;
    }
    permute(n, a, b, 0);

    System.out.println(winGames / sumGames);
  }
  private static void permute (int n, int[] a, ArrayList<Integer> b, int k){
    for(int i = k; i < b.size(); i++){
      Collections.swap(b, i, k);
      permute(n, a, b, k + 1);
      Collections.swap(b, k, i);
    }
    if(k == b.size() - 1){
      if(judge(n, a, b)){
        winGames++;
      }
    }
  }
  private static boolean judge (int n, int[] a, ArrayList<Integer> b){
    int win = 0;
    for(int i = 0; i < n; i++){
      if(a[i] > b.get(i)){
        win++;
      }
    }
    if(win > n / 2){
      return true;
    }else{
      return false;
    }
  }
}
0