QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#118544#4858. Poker Game: DecisionAntonn_114WA 5608ms3436kbC++179.5kb2023-07-03 17:07:192023-07-03 17:07:23

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-03 17:07:23]
  • 评测
  • 测评结果:WA
  • 用时:5608ms
  • 内存:3436kb
  • [2023-07-03 17:07:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

// Write down the limits of the problem here

struct Card{
    unsigned char rank, suit;
    Card() {}
    Card(const string& s) : rank(s[0]), suit(s[1]) {}
    inline bool operator<(const Card& c){
        return rank < c.rank;
    }
};

const unsigned char flush_order[] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};


unordered_map<unsigned char, int> rank_dict{
    {'A', 13},
        {'K', 12},
        {'Q', 11},
        {'J', 10},
        {'T', 9},
        {'9', 8},
        {'8', 7},
        {'7', 6},
        {'6', 5},
        {'5', 4},
        {'4', 3},
        {'3', 2},
        {'2', 1}
};

unordered_map<unsigned char, int> flush_dict{{'A', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'T', 10}, {'J', 11}, {'Q', 12}, {'K', 13}};

multiset<int> ranks;
set<int> ranks_s;
/*
inline pair<int, vector<unsigned char>> eval(vector<Card> &hand){
    ranks.clear();
    ranks_s.clear();
    bool same_suit = true;
    bool royal = true;
    bool straight = true;
    int foo = -1;
    for (auto& i : hand){
        if (foo == -1) foo = i.suit;
        else if (foo != i.suit) same_suit = false;
        ranks.insert(i.rank);
        ranks_s.insert(i.rank);
        if ('1' <= i.rank && i.rank <= '9') royal = false;
    }
    if (royal && same_suit) return {10, {'T', 'J', 'Q', 'K', 'A'}};
    if (ranks_s.size() == 5){
        vector<unsigned char> r1;
        for (auto it : ranks_s) r1.push_back(it);
        sort(r1.begin(), r1.end(), [&](const unsigned char& lhs, const unsigned char&rhs){
                return flush_dict[lhs] > flush_dict[rhs];
                });
        for (int i = 0; i < 4; i++){
            if (flush_dict[r1[i]] != flush_dict[r1[i + 1]] + 1) straight = false;
        }
        if (same_suit && straight) return {9, r1};
        if (straight) return {5, r1};
        sort(r1.begin(), r1.end(), [&](const unsigned char& lhs, const unsigned char&rhs) {
            return rank_dict[lhs] > rank_dict[rhs];
        });
        return {1, r1};
    }
    vector<unsigned char> r2;
    for (auto it : ranks){
        r2.push_back(it);
    }
    sort(r2.begin(), r2.end(), [&](const unsigned char& lhs, const unsigned char&rhs) {
            if (ranks.count(lhs) == ranks.count(rhs)) return rank_dict[lhs] > rank_dict[rhs];
            return ranks.count(lhs) > ranks.count(rhs);
            });
    if (ranks_s.size() == 2 && (ranks.count(*ranks_s.begin()) == 1 || ranks.count(*ranks_s.begin()) == 4)) return {8, r2};
    if (ranks_s.size() == 2) return {7, r2};
    if (ranks_s.size() == 5 && same_suit) return {6, r2};
    if (ranks_s.size() == 3 && (ranks.count(*ranks_s.begin()) == 3 ||
                (ranks.count(*ranks_s.begin()) == 1 && ranks.count(*next(ranks_s.begin())) == 3) ||
                (ranks.count(*ranks_s.begin()) == 1 && ranks.count(*next(ranks_s.begin())) == 1))) return {4, r2};
    if (ranks_s.size() == 3) return {3, r2};
    return {2, r2};
}*/
inline pair<int, vector<unsigned char>> eval(vector<Card> &hand){
    ranks.clear();
    ranks_s.clear();
    bool same_suit = true;
    bool royal = true;
    bool straight = false;
    int foo = -1;
    for (auto& i : hand){
        if (foo == -1) foo = i.suit;
        else if (foo != i.suit) same_suit = false;
        ranks.insert(i.rank);
        ranks_s.insert(i.rank);
        if ('1' <= i.rank && i.rank <= '9') royal = false;
    }
    if (royal && same_suit) return {10, {'T', 'J', 'Q', 'K', 'A'}};
    for (int i = 0; i < 9; i++){
        bool ok = true;
        for (int j = 0; j < 5; j++){
            if (!ranks.count(flush_order[i + j])){
                ok = false;
                continue;
            }
        }
        if (ok){
            straight = true;
            break;
        }
    }
    vector<unsigned char> r2;
    for (auto it = ranks.rbegin(); it != ranks.rend(); it++){
        r2.push_back(*it);
    }
    sort(r2.begin(), r2.end(), [&](const unsigned char& lhs, const unsigned char&rhs) {
        if (straight)
            return flush_dict[lhs] > flush_dict[rhs];
        if (ranks.count(lhs) == ranks.count(rhs)) return rank_dict[lhs] > rank_dict[rhs];
        return ranks.count(lhs) > ranks.count(rhs);
    });
    if (same_suit && straight) return {9, r2};
    if (ranks_s.size() == 2 && (ranks.count(*ranks_s.begin()) == 1 || ranks.count(*ranks_s.begin()) == 4)) return {8, r2};
    if (ranks_s.size() == 2) return {7, r2};
    if (ranks_s.size() == 5 && same_suit) return {6, r2};
    if (straight) return {5, r2};
    if (ranks_s.size() == 3 && (ranks.count(*ranks_s.begin()) == 3 ||
                                (ranks.count(*ranks_s.begin()) == 1 && ranks.count(*next(ranks_s.begin())) == 3) ||
                                (ranks.count(*ranks_s.begin()) == 1 && ranks.count(*next(ranks_s.begin())) == 1))) return {4, r2};
    if (ranks_s.size() == 3) return {3, r2};
    if (ranks_s.size() == 4) return {2, r2};
 
    return {1, r2};
}


vector<Card> Alice, Bob, Common;

int dp[64];

int main() {
    // Try to avoid cin, cout :)

    int tc = 1; cin >> tc;
    while(tc--) {
        /// Your solution here
        string s;
        Alice.clear();
        Bob.clear();
        Common.clear();
        for (int i = 0; i < 2; i++){
            cin >> s; Alice.push_back(Card(s));
        }
        for (int i =0;i < 2; i++){
            cin >> s; Bob.push_back(Card(s));
        }
        for (int i= 0; i < 6; i++){
            cin >> s; Common.push_back(Card(s));
        }
        int tmp1= 0, tmp2=0, tmp3 =0;
        for (int i = 0; i < 6; i++){
            Alice.push_back(Common[i]);
            for (int j = i + 1; j < 6; j++){
                Alice.push_back(Common[j]);
                for (int k = j + 1; k < 6; k++){
                    Alice.push_back(Common[k]);
                    for (int ii = 0; ii < 6; ii++){
                        if (ii == i || ii == j || ii == k) continue;
                        Bob.push_back(Common[ii]);
                    }
                    auto score_a = eval(Alice);
                    auto score_b = eval(Bob);
                    int winner = 0;
                    /*
                    for (auto it : Alice) cout << it.rank << it.suit << " ";
                    cout << " -> A = " << score_a.first << endl;
                     for (auto it : Bob) cout << it.rank << it.suit << " ";
                    cout << " -> B = " << score_b.first << endl;
                    */
                    if (score_a.first > score_b.first) winner = 1;
                    else if (score_b.first > score_a.first) winner = -1;
                    else{
                        for (int jj = 0; jj < 5; jj++){
                            if (score_a.second[jj]!= score_b.second[jj]){
                                if (rank_dict[score_a.second[jj]] > rank_dict[score_b.second[jj]])
                                    winner = 1;
                                else
                                    winner = -1;
                                break;
                            }
                        }
                    }
                    //cout << "WINNER " << (winner == 1 ? "A" : winner == 0 ? "DRAW" : "B") << endl;
                    dp[(1 << i) | (1 << j) | (1 << k)] = winner;
                    if (winner == 1) tmp1++;
                    if (winner == -1) tmp2++;
                    if (winner == 0) tmp3++;
                    Bob.pop_back(); Bob.pop_back(); Bob.pop_back(); 
                    Alice.pop_back();
                }
                Alice.pop_back();
            }
            Alice.pop_back();
        }
        //cout << tmp1 << " " << tmp2 << " " << tmp3 << endl;
        int winwin_a = 0, winwin_b = 0, windraw = 0;
        for (int i = 0; i < 6; i++){
            int a_win_a = 0, a_win_b = 0, a_draw = 0;
            for (int j = 0; j < 6; j++){
                if (i == j) continue;
                int b_win_a = 0, b_win_b = 0, b_draw = 0;
                for (int k = 0; k < 6; k++){
                    if (k == j || k == i) continue;
                    int win_a = 0, win_b= 0, draw = 0;

                    for (int l = 0; l < 6; l++){
                        if (l == j || l == i || l == k) continue;
                        int ss = dp[(1 << i) | (1 << k) | (1 << l)];
                        if (ss == 1) win_a++;
                        else if (ss == -1) win_b++;
                        else draw++;
                    }
                    if (win_a >= 2) b_win_a++;
                    else if (draw >= 2) b_draw++;
                    else if (win_b >= 2) b_win_b++;
                    else b_draw++;
                }
                if (b_win_a) a_win_a++;
                else if (b_draw) a_draw++;
                else a_win_b++;
            }
            if (a_win_b) winwin_b++;
            else if (a_draw) windraw++;
            else winwin_a++;
        }
        //cout << winwin_a << " " << winwin_b << " " << windraw << endl;
        if (winwin_a) cout << "Alice\n";
        else if (windraw) cout << "Draw\n";
        else cout << "Bob\n";
    }
    return 0;
}

/*
 * Ermm don't underestimate Div2A, pls...
 * 
 * IMPORTANT:: If there isn't a clear-cut approach for your program, DO NOT CODE YET!
 * 
 * Analyze the time complexity and space complexity even if it *seems* efficient
 *
 * Write down some notes for more complicated problems
 * 
 * Also, please, CP isn't supposed to be complicated
 * 
 **/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3436kb

input:

9
JC 4H
TS 5D
JS JH JD 4S 4C 4D
JC 4H
TS 5D
TH TC TD 5S 5H 5C
JC 4H
TS 5D
4S JS 5S TH TC TD
7C 3C
7H TH
3S 3H 3D 2C 4H 5S
7C 3C
7H TH
2H 4H 5H 6H 8H 9H
7C 3C
7H TH
TS 3S 2S 2H 4C 4D
2D KH
4D JC
2S 2H 2C KS KC KD
2D KH
4D JC
4S 4H 4C JS JH JD
2D KH
4D JC
2S KS 4S JS JH JD

output:

Alice
Bob
Draw
Alice
Bob
Draw
Alice
Bob
Draw

result:

ok 9 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3416kb

input:

1
AS 2H
2S 6H
3S 3H 4S 4H 5S 5H

output:

Bob

result:

ok single line: 'Bob'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3416kb

input:

1
5D 9H
KC 6H
9C QH JH 3C AC 9S

output:

Alice

result:

ok single line: 'Alice'

Test #4:

score: -100
Wrong Answer
time: 5608ms
memory: 3388kb

input:

100000
5C JS
KS 7S
4D 2D KH 6S 6D 6H
2C KS
7D 5D
5S AH 3S 9C JH 5H
9D 4D
3H TS
2D 2C 7H 3D AH 3S
KS 8H
7H QD
TH 4H QS 8S 6D TD
JS 8D
4H 2S
AH 2H 2C 6S 4C 8S
JS KD
4S 2D
JH 4C 6S QD AH 7C
9D 4H
QH JS
KH QC 6S 5D JC AD
KD 5D
4C TC
4H 2C TD 7S 6S QH
3C 5C
QC 9D
QH 5D AC 7D 8C 8S
4S 6H
9C 8C
JC 7S QH 6C...

output:

Bob
Bob
Bob
Alice
Bob
Alice
Bob
Bob
Alice
Alice
Alice
Alice
Bob
Alice
Alice
Alice
Alice
Alice
Bob
Bob
Alice
Bob
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Bob
Alice
Alice
Bob
Bob
Alice
Alice
Bob
Bob
Bob
Alice
Alice
Alice
Bob
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Al...

result:

wrong answer 1420th lines differ - expected: 'Alice', found: 'Bob'