hdu4431 Mahjong

48 篇文章 0 订阅

Mahjong

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2464 Accepted Submission(s): 522


Problem Description
Japanese Mahjong is a four-player game. The game needs four people to sit around a desk and play with a set of Mahjong tiles. A set of Mahjong tiles contains four copies of the tiles described next:

One to nine Man, which we use 1m to 9m to represent;

One to nine Sou, which we use 1s to 9s to represent;

One to nine Pin, which we use 1p to 9p to represent;

Character tiles, which are:Ton, Nan, Sei, Pei, Haku, Hatsu, Chun, which we use 1c to 7c to represent.

A winning state means a set of 14 tiles that normally contains a pair of same tiles (which we call "eyes") and four melds. A meld is formed by either three same tiles(1m, 1m, 1m or 2c, 2c, 2c for example) or three continuous non-character tiles(1m, 2m, 3m or 5s, 6s, 7s for example).

However, there are two special winning states that are different with the description above, which are:
"Chii Toitsu", which means 7 different pairs of tiles;
"Kokushi Muso", which means a set of tiles that contains all these tiles: 1m, 9m, 1p, 9p, 1s, 9s and all 7 character tiles. And the rest tile should also be one of the 13 tiles above.

And the game starts with four players receiving 13 tiles. In each round every player must draw one tile from the deck one by one. If he reaches a winning state with these 14 tiles, he can say "Tsu Mo" and win the game. Otherwise he should discard one of his 14 tiles. And if the tile he throws out can form a winning state with the 13 tiles of any other player, the player can say "Ron" and win the game.

Now the question is, given the 13 tiles you have, does there exist any tiles that can form a winning state with your tiles?

(Notes: Some of the pictures and descriptions above come from Wikipedia.)

Input
The input data begins with a integer T(1≤T≤20000). Next are T cases, each of which contains 13 tiles. The description of every tile is as above.

Output
For each cases, if there actually exists some tiles that can form a winning state with the 13 tiles given, print the number first and then print all those tiles in order as the description order of tiles above. Otherwise print a line "Nooten"(without quotation marks).

Sample Input
  
  
2 1s 2s 3s 2c 2c 2c 2p 3p 5m 6m 7m 1p 1p 1p 1p 2p 3p 4s 5s 6s 7c 7c 3s 3s 2m 2m

Sample Output
  
  
2 1p 4p Nooten

Source

Recommend
zhoujiaqi2010
细节啊,细节,要注意,wrong了一天,就是那么一点点的小bug,这题其实,因为,麻将不多,我们把所有的麻将都枚举出来就可以了!
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
char charmap[34][3]={
"1m","2m","3m","4m","5m","6m","7m","8m","9m",
"1s","2s","3s","4s","5s","6s","7s","8s","9s",
"1p","2p","3p","4p","5p","6p","7p","8p","9p",
"1c","2c","3c","4c","5c","6c","7c"};
int num19[15]={0,8,9,17,18,26,27,28,29,30,31,32,33},num[34];
int prime[34],result[40],ans,all=33;char str[13];
int charchange(char ss[])
{
    switch(ss[1])
    {
    case 'm':return ss[0]-'0'-1;
    case 's':return 8+ss[0]-'0';
    case 'p':return 17+ss[0]-'0';
    case 'c':return 26+ss[0]-'0';
    }
    return -1;
}
int find1()
{
    int i,j,k,cnt;
    for(i=0;i<=all;i++)
    {
        if(num[i]>=2)
        {
            cnt=0;
            for(j=0;j<=all;j++)
            {
                if(i!=j)prime[j]=num[j];
                else prime[j]=num[j]-2;
            }
            for(j=0;j<=all;j++)
            {
                if(prime[j]>=3)
                {
                    prime[j]-=3;
                    cnt++;
                }
                if(prime[j]>0)
                {
                    k=prime[j];
                    if(j+2<27&&prime[j+1]>=k&&prime[j+2]>=k&&j/9==(j+2)/9)
                    {
                        cnt+=k;
                        prime[j]-=k,prime[j+1]-=k,prime[j+2]-=k;
                    }
                }
            }
            if(cnt==4)
                return 1;
        }
    }
    return 0;
}
int find2()
{
    int i;
    for(i=0;i<=all;i++)
    {
        if(num[i]!=2&&num[i]!=0)
        return 0;
    }
    return 1;
}
int find3()
{
    int i,r=0;
    for(i=0;i<13;i++)
    {
        if(num[num19[i]]==0)
        return 0;
        r+=num[num19[i]];
    }
    if(r==14)
    return 1;
    return 0;
}
int main()
{
    int n,i,k,j;
    scanf("%d",&n);
    while(n--)
    {
        ans=-1;
        memset(num,0,sizeof(num));
        for(i=0;i<13;i++)
        {
            scanf("%s",str);
            num[charchange(str)]++;
        }
        //for(i=0;i<=all;i++)
            //printf("i%d %d i\n",i,num[i]);
        for(i=0;i<=all;i++)
        {
            if(num[i]>=4)
            continue;
            num[i]++;
            if(find1())
                result[++ans]=i;
            else if(find2())
                result[++ans]=i;
            else if(find3())
                result[++ans]=i;
            num[i]--;
        }
        if(ans>=0)
        {
            printf("%d",ans+1);
            for(i=0;i<=ans;i++)
            {
                printf(" %c%c",charmap[result[i]][0],charmap[result[i]][1]);
            }
            printf("\n");
        }
        else
            printf("Nooten\n");
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值