HDU 4431 Mahjong

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef long long LL;
const int maxn = 37;
const int INF = 0x3f3f3f3f;
int kase, a[maxn], ans[maxn];

///m,s,p,c


bool check43() {
    int cnt[maxn];
    for(int i = 0; i < 34; ++i) cnt[i] = a[i];

    int res = 0;
    for(int i = 0; i < 27; i += 9) {
        for(int j = 0; j < 9; ++j) {
            if(cnt[j+i] >= 3) {
                cnt[j+i] -= 3;
                res++;
            }
            while(j < 7 && cnt[i+j] && cnt[i+j+1] && cnt[i+j+2]) {
                cnt[i+j]--; cnt[i+j+1]--; cnt[i+j+2]--;
                res++;
            }
        }
    }
    for(int i = 0; i < 7; ++i) {
        if(cnt[i+27] >= 3) {
            cnt[i+27] -= 3;
            res++;
        }
    }
    if(res == 4) return true;
    else return false;
}

bool check1() {
    for(int i = 0; i < 34; ++i) {
        if(a[i] >= 2) {
            a[i] -= 2;
            if(check43()) {
                a[i] += 2;
                return true;
            }
            a[i] += 2;
        }
    }
    return false;
}

bool check2() {
    for(int i = 0; i < 34; ++i) {
        if(a[i] != 2 && a[i] != 0) return false;
    }
    return true;
}

bool check3() {
    if(!a[0] || !a[8] || !a[9] || !a[17] || !a[18] || !a[26]) return false;
    for(int i = 0; i < 7; ++i)
        if(!a[i+27]) return false;
    for(int i = 0; i < 27; i += 9){
        for(int j = 1; j < 8; j++)
          if(a[i+j] != 0) return false;
    }
    return true;
}

bool check() {
    if(check1() || check2() || check3()) return true;
    return false;
}

int main() {
    scanf("%d", &kase);
    while(kase--) {
        memset(a, 0, sizeof(a));
        for(int i = 0; i < 13; ++i) {
            char s[3]; scanf("%s", s);
            int t = s[0]-'1';

            if(s[1] == 's') t += 9;
            else if(s[1] == 'p') t += 18;
            else if(s[1] == 'c') t += 27;
            a[t]++;
        }
        int k = 0;
        for(int i = 0; i < 34; ++i) {
            a[i]++;
            if(a[i] <= 4 && check()) {
                ans[k++] = i;
            }
            a[i]--;
        }
        if(!k) { printf("Nooten\n"); continue; }
        printf("%d", k);
        char ss[5] = {'m','s','p','c'};
        for(int i = 0; i < k; ++i) {
            int t1 = ans[i]/9;
            int t2 = ans[i]%9+1;
            printf(" %d%c", t2, ss[t1]);
        }
        puts("");
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JalexDooo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值