結果

問題 No.133 カードゲーム
ユーザー kohaku_kohaku
提出日時 2016-12-09 11:08:54
言語 Java
(openjdk 23)
結果
AC  
実行時間 159 ms / 5,000 ms
コード長 1,740 bytes
コンパイル時間 2,341 ms
コンパイル使用メモリ 79,428 KB
実行使用メモリ 42,708 KB
最終ジャッジ日時 2024-06-25 03:45:04
合計ジャッジ時間 6,758 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        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();
        }
        int L=1;
        for(int i=1; i<=N; i++){
            L*=i;
        }
        int win=0;
        String [] perm = new String [L];
        makePerm(0, new int [N], new boolean [N+1], perm);
        for(int i=0; i<L; i++){
            char [] x = perm[i].toCharArray();
            int [] y = new int [N];
            for(int j=0; j<N; j++){
                y[j]=x[j]-'1';
            }
            win+=judge(N,A,B,y);
        }
        double ans = (double)win/L;
        System.out.println(ans);
    }
    static int judge(int N, int[] A, int[] B, int[] y){
        int count=0;
        for(int i=0; i<N; i++){
            if(A[y[i]]>B[i])count++;
        }
        if(2*count>N){
            return 1;
        }else{
            return 0;
        }
    }

    static int k=0;
    static String [] makePerm(int n, int[] perm, boolean[] flag, String[] p) {
        if(n==perm.length){
            p[k]=setPerm(perm);
            k++;
        }else{
            for(int i=1; i<=perm.length; i++){
                if(flag[i])continue;
                perm[n]=i;
                flag[i]=true;
                makePerm(n+1,perm,flag,p);
                flag[i]=false;
            }
        }
        return p;
    }
    static String setPerm(int[] perm) {
        String tmp="";
        for (int i: perm) {
            tmp=i+tmp;
        }
        return tmp;
    }
}
0