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种牌,依次判断是否听这牌,先枚举选出将,再枚举顺子、刻子等,递归判断。
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const char *mahjong[]={ 5 "0", 6 "1T","2T","3T","4T","5T","6T","7T","8T","9T", 7 "1S","2S","3S","4S","5S","6S","7S","8S","9S", 8 "1W","2W","3W","4W","5W","6W","7W","8W","9W", 9 "DONG","NAN","XI","BEI", 10 "ZHONG","FA","BAI", 11 }; 12 13 int n; 14 int mj[15],c[35]; 15 16 int mjid(char str[]) 17 { 18 int i,j; 19 for(i=1;i<=34;i++) 20 { 21 if(strcmp(mahjong[i],str)==0) 22 { 23 return i; 24 } 25 } 26 } 27 28 int Search(int m) 29 { 30 int i,j; 31 for(i=1;i<=34;i++) 32 { 33 if(c[i]>=3) 34 { 35 if(m==4) return 1; 36 c[i]-=3; 37 if(Search(m+1)==1) return 1; 38 c[i]+=3; 39 } 40 } 41 for(i=1;i<=25;i++) 42 { 43 if(i%9<=7 && i%9!=0 && c[i]>=1 && c[i+1]>=1 && c[i+2]>=1) 44 { 45 if(m==4) return 1; 46 c[i]--,c[i+1]--,c[i+2]--; 47 if(Search(m+1)==1) return 1; 48 c[i]++,c[i+1]++,c[i+2]++; 49 } 50 } 51 return 0; 52 } 53 54 int hu() 55 { 56 int i,j; 57 for(i=1;i<=34;i++) 58 { 59 if(c[i]>=2) 60 { 61 c[i]-=2; 62 if(Search(1)==1) 63 return 1; 64 c[i]+=2; 65 } 66 } 67 return 0; 68 } 69 int main() 70 { 71 int i,j; 72 char str[10]; 73 int cas=1; 74 while(scanf("%s",str)!=EOF) 75 { 76 if(str[0]==‘0‘) 77 break; 78 79 mj[1]=mjid(str); 80 for(i=2;i<=13;i++) 81 { 82 scanf("%s",str); 83 mj[i]=mjid(str); 84 } 85 86 printf("Case %d:",cas++); 87 88 bool flg=false; 89 for(i=1;i<=34;i++) 90 { 91 memset(c,0,sizeof(c)); 92 for(j=1;j<=13;j++) 93 c[mj[j]]++; 94 if(c[i]>=4) continue; 95 96 c[i]++; 97 if(hu()==1) 98 { 99 flg=true; 100 printf(" %s",mahjong[i]); 101 } 102 c[i]--; 103 } 104 105 if(!flg) 106 printf(" Not ready"); 107 printf("\n"); 108 } 109 return 0; 110 }
时间: 2024-10-12 03:57:51