当前位置: 代码迷 >> 综合 >> UVA 11210 Chinese Mahjong -
  详细解决方案

UVA 11210 Chinese Mahjong -

热度:42   发布时间:2023-09-23 05:49:13.0

题目地址:http://vjudge.net/problem/UVA-11210

打麻将判断糊了没有,没接触过麻将,所以题意一开始看的云里雾里的

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<=(b);i++)
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 c[41];
int convert(char* s){REP(i,0,33) if(strcmp(s,mahjong[i])==0) return i;return -1;
}
bool DFS(int dep){REP(i,0,33) if(c[i]>=3) {if(dep==3) return true;c[i]-=3;if(DFS(dep+1)) return true;c[i]+=3;}REP(i,0,24) if(i%9<=6&&c[i]>=1&&c[i+1]>=1&&c[i+2]>=1){if(dep==3) return true;c[i]--; c[i+1]--; c[i+2]--;if(DFS(dep+1)) return true;c[i]++; c[i+1]++; c[i+2]++; }return false;
}
bool Check(){REP(i,0,33) if(c[i]>=2){c[i]-=2;  //枚举将if(DFS(0)) return true;c[i]+=2;}return false;
}
int main(int argc, char const *argv[])
{int kase=0,mj[15];char s[10];while(scanf("%s",s)==1) {if(s[0]=='0') break;mj[0]=convert(s);REP(i,1,12) scanf("%s",s),mj[i]=convert(s);printf("Case %d:",++kase);bool ok=false;REP(i,0,33) {memset(c,0,sizeof(c));REP(j,0,12) c[mj[j]]++;if(c[i]>=4) continue;c[i]++;  //任意选一张牌作为听if(Check()){printf(" %s", mahjong[i]);ok=true;}c[i]--;}if(!ok) printf(" Not ready");printf("\n");}return 0;
}




  相关解决方案