题意:给出十三张牌,求听哪些牌。
被听的牌:这十四张牌可以组成4组A类牌和一组B类牌。
A:三张牌是同花色并且是顺子 或者 三张一样的牌
B:对子
牌的数量很少,直接搜。注意如果已经有四张牌就不能听了。
#include<bits/stdc++.h>
using namespace std;
string str[40] =
{
"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"
};
int a[40];
string s;
int GetNumber(string s1)
{
for(int i = 0 ; i < 34 ; i++)
{
if(str[i] == s1)
{
return i;
}
}
}
bool judge;
void dfs(int dep)
{
if(dep==4) judge = true;
for(int i = 0 ; i < 34; i++)
{
if(a[i] == 3)
{
a[i]-=3;
dfs(dep+1);
a[i]+=3;
}
}
for(int i = 0 ; i < 34 ; i++)
{
if(i % 9 <= 6 && i <= 25 )
{
if(a[i] && a[i+1] && a[i+2])
{
a[i]--;
a[i+1]--;
a[i+2]--;
dfs(dep+1);
a[i]++;
a[i+1]++;
a[i+2]++;
}
}
}
}
void check(int dep)
{
for(int i = 0 ; i < 34 ; i++)
{
if(a[i] >= 2)
{
a[i]-=2;
dfs(0);
a[i]+=2;
}
}
}
int main()
{
int kase = 1;
while(cin >> s && s != "0")
{
memset(a,0,sizeof(a));
int x = GetNumber(s);
a[x]++;
for(int i = 0 ; i < 12 ; i++)
{
cin >> s;
x = GetNumber(s);
a[x]++;
}
printf("Case %d:",kase++);
int sum = 0;
for(int i = 0 ; i < 34 ; i++)
{
if(a[i] >= 4)
{
continue;
}
a[i]++;
{
judge = false;
check(0);
if(judge)
{
cout << " " << str[i];
sum++;
}
}
a[i]--;
}
if(!sum)
{
cout<< " Not ready" <<endl;
}
else
{
cout << endl;
}
}
}