关闭

Uva 11210 - Chinese Mahjong

153人阅读 评论(0) 收藏 举报
分类:

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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:26633次
    • 积分:968
    • 等级:
    • 排名:千里之外
    • 原创:76篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条