QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#266319#4315. 简单的卡牌游戏jzh#WA 1ms3828kbC++204.7kb2023-11-26 12:44:512023-11-26 12:44:52

Judging History

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

  • [2023-11-26 12:44:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2023-11-26 12:44:51]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

const int N = 105;

typedef long long ll;

int has[5][20];
int cur = 1;
int offset;
int dfs(int play, int u, int stop) {
    if (u == 0 || u == 14) {
        return 0;
    }
    if (play == 0) {
        int ans = -1e9;
        if (has[cur][u]) {
            ans = max(ans, dfs(!play, u + offset, 0) + 1);
        }
        if (stop == 0) {
            ans = max(ans, dfs(!play, u, 1));
        } else {
            ans = max(ans, 0);
        }
        return ans;
    } else {
        int ans = 1e9;
        if (!has[cur][u]) {
            ans = min(ans, dfs(!play, u + offset, 0) - 1);
        }
        if (stop == 0) {
            ans = min(ans, dfs(!play, u, 1));
        } else {
            ans = min(ans, 0);
        }
        return ans;
    }
}
int curWin;

pair<int, int> dfsDraw(int play, int u, int stop) {
    if (u == 0 || u == 14) {
        if (curWin == 1) {
            return {0, 1};
        } else {
            return {0, -1};
        }
    }
    if (play == 0) {
        pair<int, int> ans = {-1e9, 0};
        if (has[cur][u]) {
            pair<int, int> res = dfsDraw(!play, u + offset, 0);
            res.first++;
            ans = max(ans, res);
        }
        if (stop == 0) {
            ans = max(ans, dfsDraw(!play, u, 1));
        } else {
            ans = max(ans, {0, 0});
        }
        return ans;
    } else {
        pair<int, int> ans = {1e9, 0};
        if (!has[cur][u]) {
            pair<int, int> res = dfsDraw(!play, u + offset, 0);
            res.first--;
            ans = min(ans, res);
        }

        if (stop == 0) {
            ans = min(ans, dfsDraw(!play, u, 1));
        } else {
            ans = min(ans, {0, 0});
        }


        return ans;
    }

}

int main() {
    ios::sync_with_stdio(false);
    vector<string> mycard;
    char pre = 'S';
    int cnt = 1;
    for (int i = 0; i < 26; i++) {
        string s;
        cin >> s;
        char col = s[0];
        string num;
        for (int j = 1; j < s.size(); j++) {
            num += s[j];
        }
        int p = stoi(num);
        if (pre != col) {
            cnt++;
        }
        has[cnt][p] = 1;
        pre = col;
    }
    int turn = 0;
    while (cur <= 4) {
        if (cur == 1) {
            offset = -1;
            turn += dfs(!has[cur][7], 6, 0);
            offset = 1;
            turn += dfs(!has[cur][7], 8, 0);
            if (has[cur][7]) {
                turn++;
            } else {
                turn--;
            }

        } else {
            offset = -1;
            int res = dfs(!has[cur][7], 6, 0);
            offset = 1;
            res += dfs(!has[cur][7], 8, 0);;
            if (has[cur][7]) {
                res = max(0, res + 1);
            } else {
                res = min(0, res - 1);
            }
            turn += res;
        }
        cur++;
    }
    if (turn > 0) {
        cout << "Alice";
    } else if (turn < 0) {
        cout << "Bob";
    } else if (turn == 0) {
        curWin = has[1][7];
        cur = 1;
        bool sud = true;
        pair<int, int> draw = {0, 0};
        while (cur <= 4) {
            if (cur == 1) {
                offset = -1;
                auto res = dfsDraw(!has[cur][7], 6, 0);

               // cout <<" res1 " << res.second << endl;
                sud &= (res.second != 0);
                offset = 1;
                res = dfsDraw(!has[cur][7], 8, 0);
                sud &= (res.second != 0);

                //cout <<" res2 " << res.second << endl;
            } else {
                offset = -1;
                auto res = dfsDraw(!has[cur][7], 6, 0);
                offset = 1;
                auto res2 = dfsDraw(!has[cur][7], 8, 0);
                res.first += res2.first;



                //cout <<" r1 r2 " << res.second <<" " << res.second << endl;
                if( res.second != 0 && res2.second != 0){
                    res.second = res.second + res2.second;
                }
                else{
                    res.second = 0;
                }
                if (has[cur][7]) {
                    pair<int, int> tmp = {0, 0};
                    res = max(tmp, {res.first + 1, res.second});
                } else {
                    pair<int, int> tmp = {0, 0};
                    res = min(tmp, {res.first - 1, res.second});
                }
              //  cout <<" finali si " << res.first <<"<"<<res.second << endl;
                sud &= (res.second != 0);
            }
            cur++;
        }
        if(sud ){
            cout <<"Draw";
        }
        else{
            cout << (curWin ? "Bob":"Alice");
        }



    }


}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3828kb

input:

C12 S1 C7 H7 C3 D12 S5 C9 H4 S6 D10 H2 H1 S13 S10 C6 C10 H6 S7 D2 H3 D9 C13 D6 D4 H10

output:

Bob

result:

ok single line: 'Bob'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3592kb

input:

C13 C7 C12 D11 D6 C2 D10 H1 H12 H2 S9 S10 D7 C3 H6 C6 S5 C5 D4 H4 C1 C4 D3 C8 D8 H13

output:

Bob

result:

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