結果

問題 No.133 カードゲーム
ユーザー face4face4
提出日時 2018-05-13 16:07:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,556 bytes
コンパイル時間 685 ms
コンパイル使用メモリ 73,636 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 18:52:01
合計ジャッジ時間 1,965 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>

using namespace std;

vector<string> va;
vector<string> vb;

bool check(string s , string t){
    int awin = 0, bwin = 0;
    for(int i = 0; i < s.length(); i++){
        int a = s[i]-'0';
        int b = t[i]-'0';
        if(a > b)   awin++;
        else if(a < b)  bwin++;
    }

    return awin>bwin;
}

void makePermA(string s, string t){
    if(s == "")     va.push_back(t);
    else{
        for(int i = 0; i < s.size(); i++){
            string tmps = s;
            string tmpt = t+tmps[i];
            tmps.erase(tmps.begin()+i);
            makePermA(tmps , tmpt);
        }
    }
}

void makePermB(string s, string t){
    if(s == "")     vb.push_back(t);
    else{
        for(int i = 0; i < s.size(); i++){
            string tmps = s;
            string tmpt = t+tmps[i];   
            tmps.erase(tmps.begin()+i);
            makePermB(tmps , tmpt);
        }
    }
}

int main(){
    int n;
    string a, b, c;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> c;
        a += c;
    }

    for(int i = 0; i < n; i++){
        cin >> c;
        b += c;
    }

    makePermA(a, "");
    makePermB(b, "");

    int sum = 0;
    int win = 0;
    for(vector<string>::iterator ita = va.begin(); ita != va.end(); ita++){
        string first = *ita;
        for(vector<string>::iterator itb = vb.begin(); itb != vb.end(); itb++){
            string second = *itb;
            if(check(first, second)) win++;
            sum++;
        }
    }

    cout << (double)win / sum << endl;
    return 0;
}
0