QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#681394#5614. Simple Solitairevic233333#WA 0ms3828kbC++203.1kb2024-10-27 06:49:102024-10-27 06:49:10

Judging History

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

  • [2024-10-27 06:49:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3828kb
  • [2024-10-27 06:49:10]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define pb push_back

const ld pi = 3.14159265358979323846;
const int mod = 998244353;
const ll INF = 1e18;

template<typename T>
T chmax(T a, T b) {
    return a > b ? a : b;
}

template<typename T>
T chmin(T a, T b) {
    return a > b ? b : a;
}

const int N = (int) 1e5 + 1, M = N * 2;

struct card {
    char suit;
    char rank;
};

vector<card> base;

void cardSolve(vector<card> &face_up);
bool rankSolve(vector<card> &face_up);
bool suitSolve(vector<card> &face_up);

void solve() {

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 13; ++j) {
            string str;
            cin >> str;
            card x{};
            x.rank = str[0];
            x.suit = str[1];
            base.pb(x);
        }
    }

//    for (auto &i: base) {
//        cout << i.rank << i.suit << ' ';
//    }

    int cur = 0;
    vector<card> face_up;
    face_up.pb(base[cur++]);
    face_up.pb(base[cur++]);
    face_up.pb(base[cur++]);
    // 先抽三张牌
    while (cur < 52) {
        face_up.pb(base[cur++]);
        if (face_up.size() >= 4) {
            cardSolve(face_up);
        }
    }
    cout << face_up.size() << " ";
    for (auto &i: face_up) {
        cout << i.rank << i.suit << ' ';
    }
}

int main() {
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

void cardSolve(vector<card> &face_up) {
    bool flag1 = rankSolve(face_up);
    bool flag2 = suitSolve(face_up);
    if (!flag1 && !flag2) {
        return;
    } else {
        cardSolve(face_up);
    }
}

bool rankSolve(vector<card> &face_up) {
    int test = (int) face_up.size() - 1;
    bool flag = false;
// 先检查rank相同,移除4张牌
    while (test >= 3) {
        if (face_up[test].rank == face_up[test - 3].rank) {
            face_up.
                    erase(face_up.begin() + test - 3,
                          face_up.begin() + test + 1);
            flag = true;
            break;
        } else {
            test--;
        }
    }
    if (flag) {
        rankSolve(face_up);
        return true;
    } else {
        return false;
    }
}

bool suitSolve(vector<card> &face_up) {
    int test = (int) face_up.size() - 1;
    bool flag = false;
// 再检查suit相同,移除2张牌
    while (test >= 3) {
        if (face_up[test].suit == face_up[test - 3].suit) {
            face_up.
                    erase(face_up.begin() + test,
                          face_up.begin() + test + 1);
            face_up.erase(face_up.begin() + test - 3,
                          face_up.begin() + test - 2);
            flag = true;
            break;
        } else {
            test--;
        }
    }
    if (flag) {
        suitSolve(face_up);
        return true;
    } else {
        return false;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

2 3S 9D 

result:

ok single line: '2 3S 9D '

Test #2:

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

input:

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

output:

6 KC 4S 6H TD AC 9S 

result:

ok single line: '6 KC 4S 6H TD AC 9S '

Test #3:

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

input:

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

output:

12 KH AS 5S 5D 7C 3D 2S 6S TH JD AH 9S 

result:

wrong answer 1st lines differ - expected: '12 TS AS 5S 5D 7C 3D 2S 6S TH JD AH 9S', found: '12 KH AS 5S 5D 7C 3D 2S 6S TH JD AH 9S '