結果
| 問題 | No.133 カードゲーム | 
| コンテスト | |
| ユーザー |  haraduka_ | 
| 提出日時 | 2015-01-22 23:52:12 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,552 bytes | 
| コンパイル時間 | 694 ms | 
| コンパイル使用メモリ | 88,216 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-06-25 03:27:15 | 
| 合計ジャッジ時間 | 1,408 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 19 | 
ソースコード
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<functional>
#include<utility>
#include<iterator>
#include<algorithm>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cstring>
#include<iomanip>
using namespace std;
#define len(val) static_cast<int>(val.size())
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
typedef pair<int, int> P;
int n;
int a[4], b[4];
int hikiwake = 0;
int dfs(int ba, int bb, int cnt){
    int test = 0;
    for(int i=0; i<n; i++){
        if(ba & (1<<i)) test++;
    }
    if(test == n){
        if(n%2 == 0 && cnt*2 == n){
            hikiwake++;
            return 0;
        }else if(cnt*2 > n){
            return 1;
        }else{
            return 0;
        }
    }
    int res = 0;
    for(int i=0; i<n; i++){
        if(!(ba & (1<<i))){
            for(int j=0; j<n; j++){
                if(!(bb & (1<<j))){
                    if(a[i] > b[j]){
                        res += dfs(ba|(1<<i), bb|(1<<j), cnt+1);
                    }else{
                        res += dfs(ba|(1<<i), bb|(1<<j), cnt);
                    }
                }
            }
        }
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    int t = 1;
    for(int i=1; i<=n; i++) t*=i;
    cout << (double)dfs(0, 0, 0)/t/t<< endl;
}
            
            
            
        