1 条题解

  • 0
    @ 2026-11-1 19:55:43

    占卜DIY(Divination DIY) 题解

    思路分析

    前 1212 堆牌只会在顶部放上已翻开的同点数牌、从底部抽取未翻开的牌;第 1313 堆生命牌每次从顶部依次抽取。因此只需用数组或双端队列维护每堆初始背面向下的 44 张牌,并用 openCnt[1..12] 统计每个点数已正面朝上的张数:每条命先从第 1313 堆顶部取一张牌 cur,只要 cur != 13(非 K),就令 openCnt[cur]++,再从第 cur 堆底部取出一张未翻开的牌更新 cur;遇到 K 则本条命结束。四条命结束后统计 1..12 中 openCnt[v] == 4 的点数个数即可。

    参考代码

    #include <deque>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int parseCard(const string& s)
    {
        char c = s[0];
        if (c == 'A') return 1;
        if (c == '0') return 10;
        if (c == 'J') return 11;
        if (c == 'Q') return 12;
        if (c == 'K') return 13;
        return c - '0';
    }
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        deque<int> pile[14];
        for (int i = 1; i <= 13; ++i)
        {
            for (int j = 0; j < 4; ++j)
            {
                string s;
                if (!(cin >> s)) return 0;
                pile[i].push_back(parseCard(s));
            }
        }
        int openCnt[14] = {0};
        while (!pile[13].empty())
        {
            int cur = pile[13].front();
            pile[13].pop_front();
            while (cur != 13)
            {
                openCnt[cur]++;
                int nxt = pile[cur].back();
                pile[cur].pop_back();
                cur = nxt;
            }
        }
        int ans = 0;
        for (int v = 1; v <= 12; ++v)
        {
            if (openCnt[v] == 4) ++ans;
        }
        cout << ans << "\n";
        return 0;
    }
    
    • 1

    信息

    ID
    8531
    时间
    1000ms
    内存
    512MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者