最近很颓废,一直不想写题,今天说写题结果一直拖到现在才写了一题……
一个很简单的模拟题,只要会打麻将就会写,注意牌不能超过4张的,编号的转换有点累
/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#define INF 1E9
using namespace std;
int num[40];
int s2i(char *s)
{
switch(s[0])
{
case 'D':return 1;
case 'N':return 2;
case 'X':return 3;
case 'B':if(s[1]=='E')return 4;
else return 7;
case 'Z':return 5;
case 'F':return 6;
default:
switch(s[1])
{
case 'T':return s[0]-'0'+10;
case 'S':return s[0]-'0'+20;
case 'W':return s[0]-'0'+30;
default:return 0;
}
}
}
string ss[10]={"DONG","NAN","XI","BEI","ZHONG","FA","BAI"};
string oo[10]={"0","1","2","3","4","5","6","7","8","9"};
string i2s(int now)
{
if(now<10)return ss[now-1];
switch(now/10)
{
case 1:return oo[now%10]+"T";
case 2:return oo[now%10]+"S";
case 3:return oo[now%10]+"W";
default:return "error";
}
}
bool win(int two,int three,int i)
{
if(i==40)return 0;
if(num[i]==0)return win(two,three,i+1);
if(two&&num[i]>=2)
{
if(!three)return 1;
num[i]-=2;
if(win(0,three,i)){num[i]+=2;return 1;}
num[i]+=2;
}
if(three&&num[i]>=3)
{
if(three==1&&!two)return 1;
num[i]-=3;
if(win(two,three-1,i)){num[i]+=3;return 1;}
num[i]+=3;
}
if(three&&num[i]&&i>10)
{
for(int t=-2;t<=0;t++)
{
if((i+t)/10!=(i+t+2)/10)continue;
if(!num[i+t]||!num[i+t+1]||!num[i+t+2])continue;
if(three==1&&!two)return 1;
num[i+t]--;num[i+t+1]--;num[i+t+2]--;
if(win(two,three-1,i)){num[i+t]++;num[i+t+1]++;num[i+t+2]++;return 1;}
num[i+t]++;num[i+t+1]++;num[i+t+2]++;
}
}
return 0;
}
void solve(int T)
{
cout<<"Case "<<T<<":";
bool flag=1;
for(int i=11;i!=10;i++)//因为顺序要求
{
if(!(i%10)||num[i]==4)continue;
num[i]++;
if(win(1,4,1)){cout<<" "<<i2s(i);flag=0;}
num[i]--;
if(i==39)i=0;
}
if(flag)cout<<" Not ready";
cout<<endl;
}
bool input()
{
char s[100];
int i=0;
memset(num,0,sizeof(num));
do
{
i++;
scanf("%s",s);
if(s[0]=='0')return 0;
num[s2i(s)]++;
}while(i<13);
return 1;
}
int main()
{
int T=0;
while(input())solve(++T);
}
/*
4T 5T 6T 6T 6T 6T 7T 8T 9T 9T 9T BAI BAI
4T 5T 6T 6T 6T 6T 7T 8T 9T 9T 9T 1W 1W
2T 3T 3T 3T 4T 4T 4T 5T 5T 6T 6T 7T 7T
1T 1T 2T 2T 2T 3T 3T 3T 4T 4T 5T 5T 5T
1T 1T 1T 2T 2T 3T 3T 3T 4T 4T 5T 5T 5T
1T 1T 1T 2T 2T 3T 3T 3T 4T 4T 5T 5T 6T
1T 1T 1T 2T 2T 3T 3T 3T 4T 4T 5T 6T 6T
1T 1T 1T 2T 2T 3T 3T 3T 4T 4T 6T 6T 6T
1T 1T 1T 2T 2T 3T 3T 3T 4T 5T 6T 6T 6T
1T 1T 1T 2T 2T 3T 3T 4T 4T 5T 6T 6T 6T
1T 1T 2T 2T 2T 3T 3T 4T 4T 5T 6T 6T 6T
1T 1T 2T 2T 3T 3T 3T 4T 4T 5T 6T 6T 6T
1T 1T 2T 2T 3T 3T 4T 4T 4T 5T 6T 6T 6T
1T 1T 2T 2T 3T 4T 4T 4T 4T 5T 6T 6T 6T
1T 2T 2T 2T 2T 3T 4T 4T 4T 5T 6T 6T 6T
2T 2T 2T 2T 3T 3T 4T 4T 4T 5T 6T 6T 6T
2T 2T 2T 2T 3T 3T 4T 4T 4T 5T 5T 6T 6T
1T 2T 2T 2T 3T 3T 4T 4T 4T 5T 6T 6T 6T
1T 1T 2T 2T 2T 3T 4T 4T 4T 5T 6T 6T 6T
1T 2T 2T 2T 3T 4T 4T 4T 5T 6T 6T 6T 7T
0
Case 1: 3T 9T BAI
Case 2: 3T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