結果
問題 | No.133 カードゲーム |
ユーザー |
![]() |
提出日時 | 2016-07-03 18:40:49 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 133 ms / 5,000 ms |
コード長 | 1,151 bytes |
コンパイル時間 | 3,545 ms |
コンパイル使用メモリ | 78,848 KB |
実行使用メモリ | 41,448 KB |
最終ジャッジ日時 | 2024-06-25 03:43:59 |
合計ジャッジ時間 | 7,405 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
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;}}}