Uva 11210 - Chinese Mahjong

原创 2015年07月09日 17:57:12

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

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Uva 11210 Chinese Mahjong 解题报告(枚举+码力)

Problem C Chinese Mahjong Mahjong () is a game of Chinese origin usually played by four persons ...
  • kbdwo
  • kbdwo
  • 2014年07月14日 22:08
  • 606

UVA 11210 Chinese Mahjong(中国麻将 , 大模拟)

解题思路: 关键在于如何判断十四张牌能否和牌,这里采用dfs来判断,详情看代码。 #include #include #include #include #include #includ...

UVA - 11210 Chinese Mahjong(回溯)

Problem C Chinese Mahjong Mahjong () is a game of Chinese origin usually played by four person...

中国麻将(Chinese Mahjong, UVa 11210)【JAVA算法实现】

题目描述 麻将是一个中国原创的4人玩的游戏。这个游戏有很多变种,但本题只考虑一种有136张牌的玩法。这136张牌所包含的内容如下。 饼(筒)牌:每张牌包括一系列点,每个点代表一个铜...

uva 11210 - Chinese Mahjong(暴力搜索)

uva 11210 - Chinese Mahjong(暴力搜索)
  • zjzytnn
  • zjzytnn
  • 2016年12月05日 15:04
  • 184

uva11210 Chinese Mahjong

搜索
  • sdfzyhx
  • sdfzyhx
  • 2016年11月08日 15:20
  • 139

Uva-11210-Chinese Mahjong

这个题是对麻将的一个模拟,要求求出所有可以“听"牌的可能,其实可以枚举所有的牌然后进行搜索看这张牌是否可以成为听牌,而如果拥有着张牌后能够成功的和牌,那么就说明这张牌能够成为听牌。 再添加某张牌后,...

UVA 11210 Chinese Mahjong

简单的深搜题目,但是代码写的有点冗杂,以后要注意精简代码了。 #include #include #include #include #include using namespace st...

uva 11210 Chinese Mahjong(暴力枚举)

uva 11210 Chinese Mahjong Mahjong () is a game of Chinese origin usually played by four perso...

hdu 4431 Mahjong,uva 11210 chinese Mahjong,麻将,超快的解法。。

这个代码在hdu可以进前五,运行时间是140ms(我贴的代码是156ms,不用cin cout 就可以140ms了好像) 题目就是我们熟悉的麻将,题目会给你13 张牌,你判他能不能胡,以及胡那些牌 o...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Uva 11210 - Chinese Mahjong
举报原因:
原因补充:

(最多只允许输入30个字)