1 条题解
-
0
占卜DIY(Divination DIY) 题解
思路分析
前 堆牌只会在顶部放上已翻开的同点数牌、从底部抽取未翻开的牌;第 堆生命牌每次从顶部依次抽取。因此只需用数组或双端队列维护每堆初始背面向下的 张牌,并用
openCnt[1..12]统计每个点数已正面朝上的张数:每条命先从第 堆顶部取一张牌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
- 上传者