Uva 11210 - Chinese Mahjong

Input

The input consists of at most 50 test cases. Each case consists of 13 tiles in a single line. The hand is legal (e.g. no invalid tiles, exactly 13 tiles). The last case is followed by a single zero, which should not be processed.

Output

For each test case, print the case number and a list of waiting tiles sorted in the order appeared in the problem description (1T~9T, 1S~9S, 1W~9W, DONG, NAN, XI, BEI, ZHONG, FA, BAI). Each waiting tile should be appeared exactly once. If the hand is not ready, print a message 'Not ready' without quotes.

Sample Input

1S 1S 2S 2S 2S 3S 3S 3S 7S 8S 9S FA FA
1S 2S 3S 4S 5S 6S 7S 8S 9S 1T 3T 5T 7T
0

Output for the Sample Input

Case 1: 1S 4S FA
Case 2: Not ready
#include <iostream>
#include <stdio.h> 
#include <cstring>
#include <map>
using namespace std;
string MaJiang[]={
"0T","1T","2T","3T","4T","5T","6T","7T","8T","9T",
"0S","1S","2S","3S","4S","5S","6S","7S","8S","9S",
"0W","1W","2W","3W","4W","5W","6W","7W","8W","9W",

"DONG", "NAN", "XI", "BEI", "ZHONG", "FA", "BAI"  
};
map<string,int>Pai;
int have[40];
int sumofpai;
bool dfs(int pre[])
{
    if(sumofpai==0)return true;
    int next[40], i, j;
     for(i=0; i<=36; i++)next[i]=pre[i];
    //三条
    for(i=1; i<=36; i++)
    {
        if(next[i]>=3)
        {
            next[i]-=3;
            sumofpai-=3;
            if(dfs(next))return true;
            sumofpai+=3;
            next[i]+=3;
        }
    }
    //刻子  
    for(i=1; i<=7; i++)
    {
        for(j=0; j<=20; j+=10)
        {
            if(next[i+j]>=1&&next[i+j+1]>=1&&next[i+j+2]>=1)
            {
                next[i+j]--; next[i+j+1]--; next[i+j+2]--;
                sumofpai-=3;
                if(dfs(next))return true;
                sumofpai+=3;
                next[i+j]++; next[i+j+1]++; next[i+j+2]++;
            }
        }
    }
    return false;
}
bool check(int xb)
{
   if(xb==0||xb==10||xb==20)return false;
   if(have[xb]==4)return false;
   int next[40],i;
   for(i=0; i<=36; i++)next[i]=have[i];
   next[xb]++;
   for(i=1; i<=36; i++)
   {
        if(next[i]>=2)
        {
            next[i]-=2;
            sumofpai = 12;
            if(dfs(next))return true;
            next[i]+=2;
        }
    }
   return false;
}
int main()
{
    /*for(int i=0; i<=9; i++)
    {
        printf("\"%dT\",",i);
    }printf("\n");
    for(int i=0; i<=9; i++)
    {
        printf("\"%dS\",",i);
    }printf("\n");
    for(int i=0; i<=9; i++)
    {
        printf("\"%dW\",",i);
    }printf("\n");*/
    for(int i=0; i<=36; i++)
    {
        Pai[MaJiang[i]]=i;
    }
    char s0[10];
    int cs = 1;
    while(scanf("%s",s0)!=EOF)
    {
        if(s0[0]=='0')break;
        memset(have,0,sizeof have);
        have[Pai[s0]]++;
        for(int i=1; i<13; i++)
        {
            scanf("%s",s0);
            have[Pai[s0]]++;
        }
        /*for(int i=1; i<=36; i++)
        {
            cout<<MaJiang[i]<<":"<<have[i]<<endl;
        }*/
        bool shuchu = false;
        printf("Case %d:",cs++);
        for(int i=1; i<=36; i++)
        {
           // cout<<i<<":"<<check(i)<<endl;
            if(check(i))
            {
                shuchu= true;
                cout<<" "<<MaJiang[i];
            }
        }
        if(!shuchu) printf(" Not ready");
        printf("\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值