QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#681397#5614. Simple Solitairevic233333#AC ✓0ms3848kbC++203.1kb2024-10-27 06:54:012024-10-27 06:54:02

Judging History

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

  • [2024-10-27 06:54:02]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3848kb
  • [2024-10-27 06:54:01]
  • 提交

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) {
        cardSolve(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) {
        cardSolve(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: 3812kb

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: 3812kb

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

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 TS AS 5S 5D 7C 3D 2S 6S TH JD AH 9S 

result:

ok single line: '12 TS AS 5S 5D 7C 3D 2S 6S TH JD AH 9S '

Test #4:

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

input:

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

output:

10 KC 9D TH 9H 2H AC QC TD 8D 6D 

result:

ok single line: '10 KC 9D TH 9H 2H AC QC TD 8D 6D '

Test #5:

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

input:

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

output:

4 2H 5C QD JD 

result:

ok single line: '4 2H 5C QD JD '

Test #6:

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

input:

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

output:

0 

result:

ok single line: '0 '

Test #7:

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

input:

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

output:

2 JC QC 

result:

ok single line: '2 JC QC '

Test #8:

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

input:

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

output:

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

result:

ok single line: '52 AH 2C 3D 4S 5H 6C 7D 8S 9H ... 4D 5S 6H 7C 8D 9S TH JC QD KS '

Test #9:

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

input:

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

output:

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

result:

ok single line: '52 AS 2S 3S 4H 5H 6H 7C 8C 9C ... 3C 4C 5C 6D 7D 8D QS 3H 6C 9D '

Test #10:

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

input:

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

output:

36 AH 2C 3D 4S 5H 6C 7D 8S 9H TC JD QS KH AC 2D 3S 4H 5C 6D 7S 8H 9C TD JS QH KC AD 2S 3H 4C 5D 6S 7H QC 4D KS 

result:

ok single line: '36 AH 2C 3D 4S 5H 6C 7D 8S 9H ... AD 2S 3H 4C 5D 6S 7H QC 4D KS '

Test #11:

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

input:

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

output:

16 7D KS 5C QC 9D 9S 5H 6C 8C 3C 5S 6S 8D JC 3D TC 

result:

ok single line: '16 7D KS 5C QC 9D 9S 5H 6C 8C 3C 5S 6S 8D JC 3D TC '

Test #12:

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

input:

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

output:

4 4C 4D TH JS 

result:

ok single line: '4 4C 4D TH JS '

Test #13:

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

input:

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

output:

4 6C QS AH TD 

result:

ok single line: '4 6C QS AH TD '

Test #14:

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

input:

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

output:

6 8D 6D 9C 9H JS 2D 

result:

ok single line: '6 8D 6D 9C 9H JS 2D '

Test #15:

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

input:

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

output:

4 KH JD QD 5C 

result:

ok single line: '4 KH JD QD 5C '

Test #16:

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

input:

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

output:

4 TC KS 2D QS 

result:

ok single line: '4 TC KS 2D QS '

Test #17:

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

input:

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

output:

4 7D KD 4D JC 

result:

ok single line: '4 7D KD 4D JC '

Test #18:

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

input:

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

output:

4 2C JS 7D QS 

result:

ok single line: '4 2C JS 7D QS '

Test #19:

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

input:

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

output:

10 TH AC JC AD 2H 7S 6C TS 9C 9D 

result:

ok single line: '10 TH AC JC AD 2H 7S 6C TS 9C 9D '

Test #20:

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

input:

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

output:

20 2D 4C 7S 6H 8H JH 3D KD 8C QS 4S TD AH QD 5C 7C 9C JD 6S 3S 

result:

ok single line: '20 2D 4C 7S 6H 8H JH 3D KD 8C QS 4S TD AH QD 5C 7C 9C JD 6S 3S '

Test #21:

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

input:

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

output:

0 

result:

ok single line: '0 '

Test #22:

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

input:

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

output:

22 JC 7H 8D 5S 4D AS KH 9H KD 2D 7D QC JS 2S JH 9D 3H 3C 8H KC AD JD 

result:

ok single line: '22 JC 7H 8D 5S 4D AS KH 9H KD ... JS 2S JH 9D 3H 3C 8H KC AD JD '

Test #23:

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

input:

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

output:

14 AH 2C 3D 4S 5H 6C 7D 8S 8D 9S TH JC QD KS 

result:

ok single line: '14 AH 2C 3D 4S 5H 6C 7D 8S 8D 9S TH JC QD KS '

Test #24:

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

input:

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

output:

22 AH 2C 3D 4S 5H 9H JH QC KD AS 2H 3C 4D 5S 6H 7C 8D 9S TH JC QD KS 

result:

ok single line: '22 AH 2C 3D 4S 5H 9H JH QC KD ... 4D 5S 6H 7C 8D 9S TH JC QD KS '

Test #25:

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

input:

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

output:

0 

result:

ok single line: '0 '

Test #26:

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

input:

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

output:

4 TH QH TC QC 

result:

ok single line: '4 TH QH TC QC '