暑期集训训练赛2(uva11210) 你会打麻将吗?

E - 你会打麻将吗?
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit  Status  Practice  UVA 11210  uDebug

Description

Download as PDF


麻将的公式是:mABC+nDDD+EE,所以要胡牌的话就把”听张“加到牌里去,然后dfs这三种情况看是否能成立

#include 
#include 
#include 
#include 
#include 


const char *MJ[]={"0","1T", "2T", "3T", "4T", "5T", "6T", "7T", "8T", "9T",
    "1S", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S",
    "1W", "2W", "3W", "4W", "5W", "6W", "7W", "8W", "9W",
    "DONG", "NAN", "XI", "BEI",
    "ZHONG", "FA", "BAI"};
int M[35],C[14];
char str[14][6];
bool init()
{
    for(int i=1;i<14;i++)
    {
        scanf("%s",str[i]);
        if(strcmp(str[1],MJ[0])==0) return false;
        for(int j=1;j<35;j++)
        {
            if(strcmp(str[i],MJ[j])==0){C[i]=j;M[j]++;break;}
        }
    }
    return true;
}


bool dfs(int cur)
{
    if(cur==4) return true;
    for(int i=1;i<35;i++)
    {
        if(M[i]>=3)
        {
            M[i]-=3;
            if(dfs(cur+1)) return true;
            M[i]+=3;
        }
    }
    for(int i=1;i<26;i++)
    {
        if(i%9!=0&&i%9<8&&M[i]>=1&&M[i+1]>=1&&M[i+2]>=1)
        {
            M[i]-=1;
            M[i+1]-=1;
            M[i+2]-=1;
            if(dfs(cur+1)) return true;
            M[i]+=1;
            M[i+1]+=1;
            M[i+2]+=1;
        }
    }
    return false;
}
bool judge()
{
    for(int i=1;i<35;i++)
    {


        if(M[i]<2) continue;
        M[i]-=2;
        if(dfs(0)) return true;
        M[i]+=2;


    }
    return false;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int cot=1;
    memset(M,0,sizeof(M));


    while(init())
    {
        int flag=0;
        printf("Case %d:",cot++);
        for(int i=1;i<35;i++)
        {
            memset(M,0,sizeof(M));
            for(int j=1;j<14;j++)
            {
                M[C[j]]++;
            }
            if(M[i]==4) continue;
            M[i]+=1;
            if(judge()){
                flag=1;
                printf(" %s",MJ[i]);
            }
            M[i]-=1;
        }
        if(flag==0) printf(" Not ready");
        printf("\n");
    }
    return 0;
}


你可能感兴趣的:(暑期集训)