QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#118541#4858. Poker Game: DecisionAntonn_114WA 533ms3536kbC++179.5kb2023-07-03 17:05:302023-07-03 17:05:32

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:05:32]
  • 评测
  • 测评结果:WA
  • 用时:533ms
  • 内存:3536kb
  • [2023-07-03 17:05:30]
  • 提交

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){
    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 || royal) 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
 * 
 **/

詳細信息

Test #1:

score: 0
Wrong Answer
time: 533ms
memory: 3536kb

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:

Draw
Draw
Draw
Draw
Bob
Draw
Draw
Draw
Draw

result:

wrong answer 1st lines differ - expected: 'Alice', found: 'Draw'