Mahjong HDU 4431

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值