题目链接:点击查看
题目大意:lyd学会了使用扑克DIY占卜。方法如下:一副去掉大小王的扑克共52张,打乱后均分为13堆,编号1~13,每堆4张,其中第13堆称作“生命牌”,也就是说你有4条命。这里边,4张K被称作死神。
初始状态下,所有的牌背面朝上扣下。
流程如下:
1.抽取生命牌中的最上面一张(第一张)。
2.把这张牌翻开,正面朝上,放到牌上的数字所对应编号的堆的最上边。(例如抽到2,正面朝上放到第2堆牌最上面,又比如抽到J,放到第11堆牌最上边,注意是正面朝上放)
3.从刚放了牌的那一堆最底下(最后一张)抽取一张牌,重复第2步。(例如你上次抽了2,放到了第二堆顶部,现在抽第二堆最后一张发现是8,又放到第8堆顶部.........)
4.在抽牌过程中如果抽到K,则称死了一条命,就扔掉K再从第1步开始。
5.当发现四条命都死了以后,统计现在每堆牌上边正面朝上的牌的数目,只要同一数字的牌出现4张正面朝上的牌(比如4个A),则称“开了一对”,当然4个K是不算的。
6.统计一共开了多少对,开了0对称作"极凶",1~2对为“大凶”,3对为“凶”,4~5对为“小凶”,6对为“中庸”,7~8对“小吉”,9对为“吉”,10~11为“大吉”,12为“满堂开花,极吉”。
题目分析:按照题意直接模拟即可,两层while套起来,用deque方便操作点,用vector记录答案
代码:
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const int N=110;
const string ss=" A234567890JQK";
deque<int>q[15];
int cnt[15];
int get_num(char ch)//懒得写映射了,直接暴力走吧
{
for(int i=1;i<=13;i++)
if(ch==ss[i])
return i;
}
int main()
{
// freopen("input.txt","r",stdin);
// ios::sync_with_stdio(false);
for(int i=1;i<=13;i++)//读入
{
for(int j=0;j<4;j++)
{
char s[5];
scanf("%s",s);
q[i].push_back(get_num(s[0]));
}
}
while(q[13].size())//第一层枚举第13堆
{
int cur=q[13].front();
q[13].pop_front();
while(cur!=13)//第二层模拟寻找的过程
{
cnt[cur]++;
int temp=cur;
cur=q[cur].back();
q[temp].pop_back();
}
}
int ans=0;
for(int i=1;i<=12;i++)//统计答案
if(cnt[i]==4)
ans++;
printf("%d\n",ans);
return 0;
}