UVA11210 Chinese Mahjong
生活随笔
收集整理的這篇文章主要介紹了
UVA11210 Chinese Mahjong
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
鏈接
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2151
題解
爆搜題,沒有任何剪枝
對每種情形枚舉如何處理它的最小的牌,要么組成順子,要么組成刻子
劉汝佳的思路:枚舉深度(即3,2,1),枚舉出牌方式,然后枚舉牌
代碼
//爆搜 #include <iostream> #include <algorithm> #include <map> #include <string> #define maxpos 34 using namespace std; int res[maxpos+10]; bool success; map<string,int> table; map<int,string> intable; bool check_shun(int x) {int i;if(1<=x and x<=7)return res[x] and res[x+1] and res[x+2];if(10<=x and x<=16)return res[x] and res[x+1] and res[x+2];if(19<=x and x<=25)return res[x] and res[x+1] and res[x+2];return false; } void make_table() {table["1T"]=1;table["2T"]=2;table["3T"]=3;table["4T"]=4;table["5T"]=5;table["6T"]=6;table["7T"]=7;table["8T"]=8;table["9T"]=9;table["1S"]=10;table["2S"]=11;table["3S"]=12;table["4S"]=13;table["5S"]=14;table["6S"]=15;table["7S"]=16;table["8S"]=17;table["9S"]=18;table["1W"]=19;table["2W"]=20;table["3W"]=21;table["4W"]=22;table["5W"]=23;table["6W"]=24;table["7W"]=25;table["8W"]=26;table["9W"]=27;table["DONG"]=28;table["NAN"]=29;table["XI"]=30;table["BEI"]=31;table["ZHONG"]=32;table["FA"]=33;table["BAI"]=34;map<string,int>::iterator it;for(it=table.begin();it!=table.end();it++)intable[it->second]=it->first; } void dfs(int pos) {int i;if(pos>maxpos){for(i=1;i<=maxpos;i++)if(res[i])break;if(i>maxpos)success=1;return;}if(res[pos]==0){dfs(pos+1);return;}//順子if(check_shun(pos)){for(i=pos;i<=pos+2;i++)res[i]--;dfs(pos);for(i=pos;i<=pos+2;i++)res[i]++;if(success)return;}//三連 if(res[pos]>=3){res[pos]-=3;dfs(pos);res[pos]+=3;if(success)return;} } int main() {int i, j, c, flag, cnt;make_table();string str;for(c=1;;c++){for(i=1;i<=maxpos;i++)res[i]=0;for(i=1;i<=13 and str!="0";i++)cin>>str, res[table[str]]++;if(str=="0")return 0;printf("Case %d: ",c);flag=0;for(i=1;i<=maxpos;i++)if(res[i]<4){res[i]++;success=0;for(j=1;j<=maxpos and !success;j++)if(res[j]>=2){res[j]-=2;dfs(1);res[j]+=2;}res[i]--;if(success){ if(!flag)cout<<intable[i], flag=1;else cout<<" "<<intable[i];}}if(!flag)cout<<"Not ready";cout<<endl;} }總結
以上是生活随笔為你收集整理的UVA11210 Chinese Mahjong的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 从Uber和快的、滴滴、易到App对比看
- 下一篇: 【node进阶】深入浅出websocke