wider93   4년 전

같은 문양의 카드 쌍이 하나가 아닌 입력에는 답이 여러 개 존재할 수 있게 됩니다.

amel   4년 전

동의합니다.


참고로 구글링하시면 jury 코드, input, output 찾으실 수 있습니다.

jury 코드에서는 입력 순서대로 순회하며 "이미 등장했던 문양을 가진" 카드와 앞서 등장했던 카드 2개를 뽑습니다.

moonpay   2년 전

So is it fixed now? What to do with multiple answers? 

#include <bits/stdc++.h>

using namespace std;

#define int int64_t


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    unordered_map<string, int> id;
    vector<string> cd1 = <b>{"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"<b>};
    vector<string> cd2 = <b>{"C", "D", "H", "S"};
    int cur = 0;
    for (auto &d: cd1) {
        for (auto &f: cd2) {
            id[d + f] = cur++;
        }
    }
    for (int ii = 1; ii <= t; ii++) {
        vector<string> cards(5);
        for (int i = 0; i < 5; i++) cin >> cards[i];
        vector<vector<string>> d;
        vector<int> index(5);
        iota(index.begin(), index.end(), 0LL);
        while (true) {
            vector<string> nc(5);
            for (int i = 0; i < 5; i++) nc[i] = cards[index[i]];
            string first = nc[1];
            int it = min_element(nc.begin() + 2, nc.end(), [&](string &a, string &b) {
                return id[a] < id[b];
            }) - nc.begin() - 1;

            auto mn = min_element(nc.begin() + 2, nc.end(), [&](string &a, string &b) {
                return id[a] < id[b];
            }) - nc.begin() - 2;

            auto mx = max_element(nc.begin() + 2, nc.end(), [&](string &a, string &b) {
                return id[a] < id[b];
            }) - nc.begin() - 2;

            auto last = 3 - mx - mn;
            auto f1 = first.substr(0, 1);
            auto f2 = first.substr(1, 1);
            if (f1 == "1") {
                f1 = "10";
                f2 = first.substr(2, 1);
            }
            auto pos = find(cd1.begin(), cd1.end(), f1) - cd1.begin();
            pos += it;
            if (last > mx) pos += 3;
            pos %= (int) (cd1.size());
            string newFirst = cd1[pos] + f2;
            if (nc[0] == newFirst) {
                d.push_back(nc);
            }

            if (!next_permutation(index.begin(), index.end())) break;
        }
        sort(d.begin(), d.end(), [&](vector<string> &a, vector<string> &b) {
            for (int i = 0; i < 5; i++) if (a[i] != b[i]) return id[a[i]] < id[b[i]];
            return true;
        });
        for (int i = 0; i < 5; i++) {
            cout << d[0][i] << " ";
        }
        if (ii != t) cout << "\n";
    }
}

댓글을 작성하려면 로그인해야 합니다.