QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#266334#4315. 简单的卡牌游戏jzh#AC ✓0ms3824kbC++204.9kb2023-11-26 13:04:442023-11-26 13:04:44

Judging History

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

  • [2023-11-26 13:04:44]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3824kb
  • [2023-11-26 13:04:44]
  • 提交

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);
    char pre = 'S';
    int cnt = 1;


    for (int i = 0; i < 26; i++) {
        string s;
        cin >> s;
        char col = s[0];
        if(col == 'S'){
            cnt = 1;
        }
        else if(col == 'D'){
            cnt = 2;
        }
        else if(col == 'C'){
            cnt = 3;
        }
        else if(col == 'H'){
            cnt = 4;
        }
        string num;
        for (int j = 1; j < s.size(); j++) {
            num += s[j];
        }
        int p = stoi(num);
        has[cnt][p] = 1;
    }

    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;
        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){ // -1 -1 or 1 1
                    res.second = res.second + res2.second;
                }
                else{// 0 x
                    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");
        }



    }


}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

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: 0
Accepted
time: 0ms
memory: 3580kb

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:

Alice

result:

ok single line: 'Alice'

Test #3:

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

input:

C5 H9 S12 D6 S10 C2 D11 S11 H5 C6 C12 C9 S4 D3 S7 S9 H1 H2 C3 S6 D1 S5 D2 H3 D12 C1

output:

Bob

result:

ok single line: 'Bob'

Test #4:

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

input:

D1 H9 H5 S4 D13 S8 H12 S5 D9 D5 C10 C8 D4 S12 S13 C4 H10 D6 H11 H8 C12 H2 S2 S6 H1 H13

output:

Bob

result:

ok single line: 'Bob'

Test #5:

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

input:

H2 D2 C9 H4 H10 C1 D1 D8 H7 C10 C3 S3 D10 S13 D6 C13 D5 C6 S8 H11 H3 H9 S4 S6 D13 H6

output:

Alice

result:

ok single line: 'Alice'

Test #6:

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

input:

C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C13 D1 D2 D3 D4 D5 D6 D7 D8 D9 D10 D11 D12 D13

output:

Draw

result:

ok single line: 'Draw'

Test #7:

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

input:

S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 S11 S12 S13 H1 H2 H3 H4 H5 H6 H7 D1 D2 D3 D4 D5 D6


output:

Draw

result:

ok single line: 'Draw'

Test #8:

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

input:

S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 S11 S12 S13 C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 D12

output:

Draw

result:

ok single line: 'Draw'

Test #9:

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

input:

S2 S4 S6 S8 S10 S12 H1 H3 H5 H7 H9 H11 H13 C1 C3 C5 C7 C9 C11 C13 D2 D4 D6 D8 D10 D12

output:

Alice

result:

ok single line: 'Alice'