20140731 【南华大学 ACM】 1270 MaJiang

http://oj.cs203.net/problem.php?id=1270


【题解】:

给定14张麻将牌,规定了‘eyes’,判断能不能和。模拟题。


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int a[3][20], ans, f[20];

int solve111(int f[]){
    int ret = 0;
    for(int i=1; i<=9; i++){
        if( f[i] && f[i+1] && f[i+2] ){
            f[i]--; f[i+1]--; f[i+2]--;
            i--;
        }
        else if( f[i]>=3 ){
            f[i] -= 3;
            i--;
        }
        else if( f[i]==2 || f[i]==1 )
            return 1;
    }
    return 100;
}

int solve34(int f[]){
    int ret = 0;
    for(int i=1; i<=9; i++){
        if( f[i]>=3 ){
            f[i] -= 3;
            i--;
        }
        else if( f[i] && f[i+1] && f[i+2] ){
            f[i]--; f[i+1]--; f[i+2]--;
            i--;
        }
        else if( f[i]==2 || f[i]==1 )
            return 1;
    }
    return 100;
}

int main(){         
    int T;
    int no, wn, tn, bn, no1, no2;
    char ch, ch1, ch2;
    while( EOF != scanf("%d", &T) ){
        while( T-- ){
            memset(a, 0, sizeof(a));
            scanf("%d %c %d %c", &no1, &ch1, &no2, &ch2);
            for(int i=2; i<14; i++){        
                scanf("%d %c", &no, &ch);     
                if( 'W'==ch )       a[0][no]++;
                else if( 'T'==ch )  a[1][no]++;
                else if( 'B'==ch )  a[2][no]++;
            }
            if( no1 != no2 || ch1 != ch2 ){
                printf("No\n");
                continue;
            }
            ans = 1;
            for(int i=0; i<3; i++){
                for(int j=1; j<10; j++) f[j] = a[i][j];
                int s1 = solve111(a[i]);
                int s2 = solve34(f);
                int now = max(s1,s2);
                if( now!=100 ){
                    ans=0;
                    break;
                }
            }
            printf("%s\n", ans?"Yes":"No");
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值