#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int M=34;
char ch[35][5]={"1m","2m","3m","4m","5m","6m","7m","8m","9m",
"1s","2s","3s","4s","5s","6s","7s","8s","9s",
"1p","2p","3p","4p","5p","6p","7p","8p","9p",
"1c","2c","3c","4c","5c","6c","7c"};
char s[15][5];
int num[35];
int cnt[35];
int tot;
int ans[35];
/*
5
1m 1m 1m 3m 3m 3m 5m 5m 5m 9m 9m 9m 1s
*/
bool Cal_1(){
int ret=0;
int i,j,k;
for(i=0;i<M;i++){
if(num[i]<2)continue;
for(j=0;j<M;j++)
if(i==j) cnt[j]=num[j]-2;
else cnt[j]=num[j];
int flag=0;
for(j=0;j<M;j++){
if(j<27){
if(cnt[j]<=2){
int tp=cnt[j];
if(j+2<27 && cnt[j+1]>=tp && cnt[j+2]>=tp && j/9==(j+2)/9){
cnt[j+1]-=tp;
cnt[j+2]-=tp;
cnt[j]=0;
flag+=tp;
}
}else if(cnt[j]==3){
cnt[j]=0;
flag++;
}else if(cnt[j]==4){
cnt[j]-=3;
flag++;
j--;
}
}else{
if(cnt[j]>=3)
flag++;
}
}
if(flag==4){
ret=1;
break;
}
}
return ret;
}
bool Cal_2(){
int ret=0;
for(int i=0;i<M;i++)
if(num[i]==2)
ret++;
return ret==7;
}
int g[15]={0,8,9,17,18,26,27,28,29,30,31,32,33};
bool Cal_3(){
int ret=0;
for(int i=0;i<13;i++){
if(num[g[i]]==0)
return 0;
ret+=num[g[i]];
}
return ret==14;
}
int main(){
int T;
int i,j;
scanf("%d",&T);
while(T--){
memset(num,0,sizeof(num));
for(i=0;i<13;i++){
scanf("%s",s[i]);
for(j=0;j<M;j++)
if(strcmp(s[i],ch[j])==0)
num[j]++;
}
tot=0;
for(i=0;i<M;i++){
if(num[i]>=4)continue;
num[i]++;
if(Cal_2()){
ans[tot++]=i;
}else if(Cal_3()){
ans[tot++]=i;
}else if(Cal_1()){
ans[tot++]=i;
}
num[i]--;
}
if(tot==0)
puts("Nooten");
else{
printf("%d",tot);
for(i=0;i<tot;i++)
printf(" %s",ch[ans[i]]);
puts("");
}
}
return 0;
}
Mahjong HDU 4431
最新推荐文章于 2019-07-10 17:43:59 发布