Problem Description
Japanese Mahjong is a four-player game. The game needs four people to sit around a desk and play with a set of Mahjong tiles. A set of Mahjong tiles contains four copies of the tiles described next:
One to nine Man, which we use 1m to 9m to represent;
One to nine Sou, which we use 1s to 9s to represent;
One to nine Pin, which we use 1p to 9p to represent;
Character tiles, which are:Ton, Nan, Sei, Pei, Haku, Hatsu, Chun, which we use 1c to 7c to represent.
A winning state means a set of 14 tiles that normally contains a pair of same tiles (which we call "eyes") and four melds. A meld is formed by either three same tiles(1m, 1m, 1m or 2c, 2c, 2c for example) or three continuous non-character tiles(1m, 2m, 3m or 5s, 6s, 7s for example).
However, there are two special winning states that are different with the description above, which are:
"Chii Toitsu", which means 7 different pairs of tiles;
"Kokushi Muso", which means a set of tiles that contains all these tiles: 1m, 9m, 1p, 9p, 1s, 9s and all 7 character tiles. And the rest tile should also be one of the 13 tiles above.
And the game starts with four players receiving 13 tiles. In each round every player must draw one tile from the deck one by one. If he reaches a winning state with these 14 tiles, he can say "Tsu Mo" and win the game. Otherwise he should discard one of his 14 tiles. And if the tile he throws out can form a winning state with the 13 tiles of any other player, the player can say "Ron" and win the game.
Now the question is, given the 13 tiles you have, does there exist any tiles that can form a winning state with your tiles?
(Notes: Some of the pictures and descriptions above come from Wikipedia.)
One to nine Man, which we use 1m to 9m to represent;
One to nine Sou, which we use 1s to 9s to represent;
One to nine Pin, which we use 1p to 9p to represent;
Character tiles, which are:Ton, Nan, Sei, Pei, Haku, Hatsu, Chun, which we use 1c to 7c to represent.
A winning state means a set of 14 tiles that normally contains a pair of same tiles (which we call "eyes") and four melds. A meld is formed by either three same tiles(1m, 1m, 1m or 2c, 2c, 2c for example) or three continuous non-character tiles(1m, 2m, 3m or 5s, 6s, 7s for example).
However, there are two special winning states that are different with the description above, which are:
"Chii Toitsu", which means 7 different pairs of tiles;
"Kokushi Muso", which means a set of tiles that contains all these tiles: 1m, 9m, 1p, 9p, 1s, 9s and all 7 character tiles. And the rest tile should also be one of the 13 tiles above.
And the game starts with four players receiving 13 tiles. In each round every player must draw one tile from the deck one by one. If he reaches a winning state with these 14 tiles, he can say "Tsu Mo" and win the game. Otherwise he should discard one of his 14 tiles. And if the tile he throws out can form a winning state with the 13 tiles of any other player, the player can say "Ron" and win the game.
Now the question is, given the 13 tiles you have, does there exist any tiles that can form a winning state with your tiles?
(Notes: Some of the pictures and descriptions above come from Wikipedia.)
Input
The input data begins with a integer T(1≤T≤20000). Next are T cases, each of which contains 13 tiles. The description of every tile is as above.
Output
For each cases, if there actually exists some tiles that can form a winning state with the 13 tiles given, print the number first and then print all those tiles in order as the description order of tiles above. Otherwise print a line
"Nooten"(without quotation marks).
Sample Input
2 1s 2s 3s 2c 2c 2c 2p 3p 5m 6m 7m 1p 1p 1p 1p 2p 3p 4s 5s 6s 7c 7c 3s 3s 2m 2m
Sample Output
2 1p 4p Nooten
题意:打麻将,给你十三张牌,问你听哪张牌。胡法除了平常的33332以外,还有两种特殊的。七对:任意七对不一样的牌。十三幺:东南西北中发白各一张,一九万一九索一九筒,再加一张跟前面十三张一样的。
注意每种牌最多四张。
就按它给的顺序一个个把牌加进去,判断加进这张牌后能不能胡就好。
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<vector> #include<string> #include<stack> #include<cstring> using namespace std; #define rep(i,f,t) for(int i = (f), _end = (t); i <= _end; ++i) typedef long long int64; #define debug(x) cout<<"debug "<<x<<endl; #define clr(cnt,x) memset(cnt,x,sizeof(cnt)); const int maxn = 1000000000+5; int n,m; int p[5][10]; //p[4]表示字牌,123是普通牌 string out[5][10]; void pre(){ char tmp[3];clr(tmp,0); rep(i,1,9){ tmp[0] = i+'0'; tmp[1] = 'm'; out[1][i] = string(tmp); } rep(i,1,9){ tmp[0] = i+'0'; tmp[1] = 's'; out[2][i] = string(tmp); } rep(i,1,9){ tmp[0] = i+'0'; tmp[1] = 'p'; out[3][i] = string(tmp); } rep(i,1,7){ tmp[0] = i+'0'; tmp[1] = 'c'; out[4][i] = string(tmp); } } vector<string> ans; void input(){ int d; char c; scanf("%d%c",&d,&c); if(c == 'm')p[1][d]++; else if(c == 's')p[2][d]++; else if(c == 'p')p[3][d]++; else if(c == 'c')p[4][d]++; } bool pr(){ //判断七对 rep(i,1,4)rep(j,1,9)if(p[i][j] != 0 && p[i][j] != 2)return false; return true; } bool ss(){ //判断十三幺 bool flg = 0; rep(j,1,7){ if(!p[4][j] || p[4][j] > 2)return false; if(p[4][j] == 2){ if(flg)return false; flg = 1; } } rep(i,1,3){ for(int j = 1; j < 10; j += 8){ if(!p[i][j] || p[i][j] > 2)return false; if(p[i][j] == 2){ if(flg)return false; flg = 1; } } } return flg; } int ok[5]; int pai[15]; bool deal(int i){ //单判i类型牌能不能成三 clr(pai,0); int sum = 0; rep(j,1,9){ pai[j] = p[i][j]; sum += pai[j]; } if(sum%3)return false; for(i = 1; i <= 9; ++i){ if(pai[i]==0)continue; if(pai[i]==3)continue; if(pai[i] == 4)pai[i] = 1; if((pai[i+1] -= pai[i]) < 0)return false; if((pai[i+2] -= pai[i]) < 0)return false; } return true; } void prefind(){ clr(ok,0); rep(i,1,3)if(deal(i))ok[i]=1; } bool jg(){ rep(j,1,7)if(p[4][j] == 4)return false; //字牌有四张肯定不能胡 if(pr())return true; if(ss())return true; bool flg = 0; rep(j,1,7){ if(p[4][j]==1)return false; if(p[4][j]==2){ if(flg)return false; flg = 1; } } if(flg){ //眼在字牌 prefind(); int sok = ok[1]+ok[2]+ok[3]; if(sok==3)return true; else return false; } int sum[4];clr(sum,0); rep(i,1,3)rep(j,1,9)sum[i] += p[i][j]; int tmp = 0; rep(i,1,3)if(sum[i]%3==2){ if(tmp)return false; tmp = i; //找到眼的牌型 } if(tmp == 0)return false; rep(i,1,3)if(i!=tmp){ if(!deal(i))return false; } int i = tmp; rep(j,1,9){ if(p[i][j] >= 2){ //枚举眼的位置 p[i][j] -= 2; //把眼去掉 if(deal(i)){ p[i][j] += 2; //注意这里别漏了加回去 return true; } p[i][j] += 2; } } return false; } int main(){ pre(); int T; scanf("%d",&T); while(T--){ ans.clear(); clr(p,0); rep(i,1,13) input(); rep(j,1,7)if(p[4][j] == 4){ printf("Nooten "); goto endd; } rep(i,1,3){ rep(j,1,9){ if(p[i][j] == 4)continue; p[i][j]++; if(jg())ans.push_back(out[i][j]); p[i][j]--; } } rep(j,1,7){ if(p[4][j] >= 3)continue; p[4][j]++; if(jg())ans.push_back(out[4][j]); p[4][j]--; } if(ans.size() == 0)printf("Nooten "); else{ printf("%d",ans.size()); for(int i = 0; i < ans.size(); ++i){ printf(" %s",ans[i].c_str()); } printf(" "); } endd: ; } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。