結果
問題 | No.133 カードゲーム |
ユーザー |
![]() |
提出日時 | 2018-11-07 15:46:30 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 138 ms / 5,000 ms |
コード長 | 1,448 bytes |
コンパイル時間 | 2,810 ms |
コンパイル使用メモリ | 77,944 KB |
実行使用メモリ | 41,808 KB |
最終ジャッジ日時 | 2024-11-20 20:44:16 |
合計ジャッジ時間 | 6,293 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
import java.io.File;import java.io.IOException;import java.util.*;public class Main {public static void main(String[] args) throws IOException {//File file = new File("input.txt");//Scanner sc = new Scanner(file);Scanner sc = new Scanner(System.in);int N = sc.nextInt();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();ArrayList<Integer> list = new ArrayList<Integer>();int[] d = dfs(list, A, B, N);//System.out.println(d[0] + " " + d[1] + " ");System.out.println((1.0 * d[0] / d[1]));}public static int[] dfs(ArrayList<Integer> cardIndexList, int[] A, int[] B, int N){int winNum = 0;int battleNum = 0;if(cardIndexList.size() == N){int count = 0;for(int i = 0; i < N; i++){//System.out.print(A[cardIndexList.get(i)]);if(A[cardIndexList.get(i)] > B[i]) count++;if(A[cardIndexList.get(i)] < B[i]) count--;}//System.out.println();battleNum = 1;if(count >= 1) winNum = 1;else winNum = 0;}else{for(int i = 0; i < N; i++){if(!cardIndexList.contains(i)){ArrayList<Integer> nextList = new ArrayList<Integer>();for(Integer m : cardIndexList) nextList.add(m);nextList.add(i);int[] d = dfs(nextList, A, B, N);winNum += d[0];battleNum += d[1];}}}int[] d = {winNum, battleNum};return d;}}