求助麻将 WA
查看原帖
求助麻将 WA
574944
Micnation_AFO楼主2022/5/21 18:13

如题。输出格式已经调整地跟题解差不多了,但还是 WA。

求神犇帮忙

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define x 13
#define maxn 55
const string card[] = { "1T","2T","3T","4T","5T","6T","7T","8T","9T",
                        "1S","2S","3S","4S","5S","6S","7S","8S","9S",
                        "1W","2W","3W","4W","5W","6W","7W","8W","9W",
                        "DONG","NAN","XI","BEI","ZHONG","FA","BAI" };
map<string, int> m;
vector<string> v;
int cnt[maxn], i;
bool vis[maxn]; 

void dfs(int num, string s) {
    if (num == 0) { v.push_back(s); vis[m[s]] = true; return; }
    for (int i = 0; i < 34; i++) {
        if (vis[m[s]] == true) return;
        if (cnt[i] >= 3) {
            cnt[i] -= 3;
            dfs(num - 3, s);
            cnt[i] += 3;
        }
        if (vis[m[s]] == true) return;
        if (cnt[i] && cnt[i + 1] && cnt[i + 2]) {
            cnt[i]--, cnt[i + 1]--, cnt[i + 2]--;
            dfs(num - 3, s);
            cnt[i]++, cnt[i + 1]++, cnt[i + 2]++;
        }
    }
}

void check(string s) {
    for (int i = 0; i < 34; i++) {
        if (cnt[i] >= 2) {
            cnt[i] -= 2;
            dfs(12, s);            
            cnt[i] += 2;
        }
    }
}

signed main() {
    for (int i = 0; i < 34; i++) m[card[i]] = i;
    while (1) {
        memset(cnt, 0, sizeof(cnt));
        v.clear();
        for (int i = 1; i <= x; i++) {
            string s; cin >> s;
            if (s == "0") return 0;
            cnt[m[s]]++;
        }
        for (int i = 0; i < 34; i++) {
            if (cnt[i] >= 4) continue;
            cnt[i]++;
            check(card[i]);         
            cnt[i]--; 
        }
        cout << "Case " << ++i << ":";
        if (v.empty()) cout << " Not ready" << endl;
        else {
            for (vector<string> :: iterator it = v.begin(); it != v.end(); it++) cout << " "<< *it;
            cout << endl;
        }
    }
    return 0;
}

2022/5/21 18:13
加载中...