QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#82046#4858. Poker Game: DecisionSorting#WA 20ms11628kbC++147.5kb2023-02-26 23:42:402023-02-26 23:45:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-26 23:45:19]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:11628kb
  • [2023-02-26 23:42:40]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>

using namespace std;

int alice[2], bob[2];
int shared[6];

pair<int, int> p[14][14][14][14][14][2];

void init(){
    static int a[5];
    for(int a0 = 1; a0 <= 13; ++a0)
        for(int a1 = 1; a1 <= 13; ++a1)
            for(int a2 = 1; a2 <= 13; ++a2)
                for(int a3 = 1; a3 <= 13; ++a3)
                    for(int a4 = 1; a4 <= 13; ++a4){
                        for(int a_flush = 0; a_flush <= 1; ++a_flush){
                            a[0] = a0;
                            a[1] = a1;
                            a[2] = a2;
                            a[3] = a3;
                            a[4] = a4;
                            sort(a, a + 5);

                            bool a_straight = true;
                            for(int i = 0; i < 4; ++i)
                                a_straight &= (a[i] == a[i - 1] + 1) || (a[i] == 1 && a[i - 1] == 13);
                            
                            auto &ans = p[a0][a1][a2][a3][a4][a_flush];

                            int a_score = 0;
                            if(a_straight && a_flush)
                                a_score = a[0];

                            if(a_score){
                                ans = {9, a_score};
                                continue;
                            }

                            if(a[0] == a[3])
                                a_score = 16 * a[0] + a[4];
                            else if(a[1] == a[4])
                                a_score = 16 * a[1] + a[0];

                            if(a_score){
                                ans = {8, a_score};
                                continue;
                            }

                            if(a[0] == a[2] && a[3] == a[4])
                                a_score = 16 * a[0] + a[3];
                            else if(a[0] == a[1] && a[2] == a[4])
                                a_score = 16 * a[2] + a[0];

                            if(a_score){
                                ans = {7, a_score};
                                continue;
                            }

                            if(a_flush)
                                a_score = 16 * 16 * 16 * 16 * a[0] + 16 * 16 * 16 * a[1] + 16 * 16 * a[2] + 16 * a[3] + a[4];

                            if(a_score){
                                ans = {6, a_score};
                                continue;
                            }

                            if(a_straight)
                                a_score = a[0];
                            
                            if(a_score){
                                ans = {5, a_score};
                                continue;
                            }

                            if(a[0] == a[2])
                                a_score = 16 * 16 * a[0] + 16 * a[3] + a[4];
                            else if(a[1] == a[3])
                                a_score = 16 * 16 * a[1] + 16 * a[0] + a[4];
                            else if(a[2] == a[4])
                                a_score = 16 * 16 * a[2] + 16 * a[0] + a[1];

                            if(a_score){
                                ans = {4, a_score};
                                continue;
                            }

                            if(a[0] == a[1] && a[2] == a[3])
                                a_score = 16 * 16 * a[0] + 16 * a[2] + a[4];
                            else if(a[0] == a[1] && a[3] == a[4])
                                a_score = 16 * 16 * a[0] + 16 * a[3] + a[2];
                            else if(a[1] == a[2] && a[3] == a[4])
                                a_score = 16 * 16 * a[1] + 16 * a[3] + a[0];

                            if(a_score){
                                ans = {3, a_score};
                                continue;
                            }

                            if(a[0] == a[1])
                                a_score = a[0] * 16 * 16 * 16 + a[2] * 16 * 16 + a[3] * 16 + a[4];
                            else if(a[1] == a[2])
                                a_score = a[1] * 16 * 16 * 16 + a[0] * 16 * 16 + a[3] * 16 + a[4];
                            else if(a[2] == a[3])
                                a_score = a[2] * 16 * 16 * 16 + a[0] * 16 * 16 + a[1] * 16 + a[4];
                            else if(a[3] == a[4])
                                a_score = a[3] * 16 * 16 * 16 + a[0] * 16 * 16 + a[2] * 16 + a[3];

                            if(a_score){
                                ans = {2, a_score};
                                continue;
                            }

                            a_score = a[0] * 16 * 16 * 16 * 16 + a[1] * 16 * 16 * 16 + a[2] * 16 * 16 + a[3] * 16 + a[4];
                            ans = {1, a_score};
                        }
                    }
}

int outcome(int state){
    static int a[5], b[5];
    a[0] = alice[0];
    a[1] = alice[1];
    b[0] = bob[0];
    b[1] = bob[1];

    int cnt_a = 2, cnt_b = 2;
    for(int i = 0; i < 6; ++i){
        if(state >> (2 * i) & 1)
            a[cnt_a++] = shared[i];
        else
            b[cnt_b++] = shared[i];
    }

    bool a_flush = true;
    for(int i = 0; i < 5; ++i)
        a_flush &= (a[i] & 3) == (a[i + 1] & 3);
    bool b_flush = true;
    for(int i = 0; i < 5; ++i)
        b_flush &= (b[i] & 3) == (b[i + 1] & 3);

    for(int i = 0; i < 5; ++i){
        a[i] >>= 2;
        b[i] >>= 2;
    }

    auto score_a = p[a[0]][a[1]][a[2]][a[3]][a[4]][a_flush];
    auto score_b = p[b[0]][b[1]][b[2]][b[3]][b[4]][b_flush];
    return (score_a > score_b) - (score_a < score_b);
}

int recurse(int state){
    int turns = __builtin_popcount(state);
    if(turns == 6){
        // cout << state << " - " << outcome(state) << endl;
        return outcome(state);
    }

    int ans;
    bool pl = turns & 1;
    ans = -1 + 2 * pl;

    for(int i = 0; i < 6; ++i){
        if(state >> (2 * i) & 3)
            continue;
        
        int cand = recurse(state + (1 << (2 * i + pl)));
        if(cand == 1 - 2 * pl)
            return cand;

        if(pl)
            ans = min(ans, cand);
        else
            ans = max(ans, cand);
    }
    return ans;
}

int string_to_card(const string &s){
    int ans = 0;
    if('2' <= s[0] && s[0] <= '9')
        ans = s[0] - '0' - 1;
    else if(s[0] == 'T')
        ans = 9;
    else if(s[0] == 'J')
        ans = 10;
    else if(s[0] == 'Q')
        ans = 11;
    else if(s[0] == 'K')
        ans = 12;
    else 
        ans = 13;
    ans *= 4;

    if(s[1] == 'S')
        ans += 0;
    else if(s[1] == 'H')
        ans += 1;
    else if(s[2] == 'C')
        ans += 1;
    else
        ans += 2;
    return ans;
}

void solve(){
    for(int i = 0; i < 2; ++i){
        string s;
        cin >> s;
        alice[i] = string_to_card(s);
    }
    for(int i = 0; i < 2; ++i){
        string s;
        cin >> s;
        bob[i] = string_to_card(s);
    }
    for(int i = 0; i < 6; ++i){
        string s;
        cin >> s;
        shared[i] = string_to_card(s);
    }

    int answer = recurse(0);
    if(answer == 1)
        cout << "Alice\n";
    else if(answer == 0)
        cout << "Draw\n";
    else
        cout << "Bob\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    init();

    int t;
    cin >> t;

    while(t--)
        solve();
}

详细

Test #1:

score: 0
Wrong Answer
time: 20ms
memory: 11628kb

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
Alice
Draw
Alice
Bob
Draw

result:

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