https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2151

http://7xjob4.com1.z0.glb.clouddn.com/f1186ae9a93d903ab533e5fce524bac6

题意:给你一副手牌,输出这手牌所有的听牌

思路:枚举所有34种牌,依次判断是否听这牌,先枚举选出将,再枚举顺子、刻子等,递归判断。

 #include <bits/stdc++.h>
using namespace std; const char *mahjong[]={
"",
"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 n;
int mj[],c[]; int mjid(char str[])
{
int i,j;
for(i=;i<=;i++)
{
if(strcmp(mahjong[i],str)==)
{
return i;
}
}
} int Search(int m)
{
int i,j;
for(i=;i<=;i++)
{
if(c[i]>=)
{
if(m==) return ;
c[i]-=;
if(Search(m+)==) return ;
c[i]+=;
}
}
for(i=;i<=;i++)
{
if(i%<= && i%!= && c[i]>= && c[i+]>= && c[i+]>=)
{
if(m==) return ;
c[i]--,c[i+]--,c[i+]--;
if(Search(m+)==) return ;
c[i]++,c[i+]++,c[i+]++;
}
}
return ;
} int hu()
{
int i,j;
for(i=;i<=;i++)
{
if(c[i]>=)
{
c[i]-=;
if(Search()==)
return ;
c[i]+=;
}
}
return ;
}
int main()
{
int i,j;
char str[];
int cas=;
while(scanf("%s",str)!=EOF)
{
if(str[]=='')
break; mj[]=mjid(str);
for(i=;i<=;i++)
{
scanf("%s",str);
mj[i]=mjid(str);
} printf("Case %d:",cas++); bool flg=false;
for(i=;i<=;i++)
{
memset(c,,sizeof(c));
for(j=;j<=;j++)
c[mj[j]]++;
if(c[i]>=) continue; c[i]++;
if(hu()==)
{
flg=true;
printf(" %s",mahjong[i]);
}
c[i]--;
} if(!flg)
printf(" Not ready");
printf("\n");
}
return ;
}
05-11 11:15