Mahjong HDU4431 略有难度的恶心模拟题
Mahjong
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3110 Accepted Submission(s): 620
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:
![](http://acm.hdu.edu.cn/data/images/4431-1.jpg)
One to nine Man, which we use 1m to 9m to represent;
![](http://acm.hdu.edu.cn/data/images/4431-2.jpg)
One to nine Sou, which we use 1s to 9s to represent;
![](http://acm.hdu.edu.cn/data/images/4431-3.jpg)
One to nine Pin, which we use 1p to 9p to represent;
![](http://acm.hdu.edu.cn/data/images/4431-4.jpg)
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.)
![](http://acm.hdu.edu.cn/data/images/4431-1.jpg)
One to nine Man, which we use 1m to 9m to represent;
![](http://acm.hdu.edu.cn/data/images/4431-2.jpg)
One to nine Sou, which we use 1s to 9s to represent;
![](http://acm.hdu.edu.cn/data/images/4431-3.jpg)
One to nine Pin, which we use 1p to 9p to represent;
![](http://acm.hdu.edu.cn/data/images/4431-4.jpg)
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
Source
Recommend
zhoujiaqi2010
/* * Author: * Created Time: 2013/10/19 19:29:35 * File Name: G.cpp * solve: G.cpp */ #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<string> #include<map> #include<stack> #include<set> #include<iostream> #include<vector> #include<queue> //ios_base::sync_with_stdio(false); //#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; #define sz(v) ((int)(v).size()) #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define repf(i, a, b) for (int i = (a); i <= (b); ++i) #define repd(i, a, b) for (int i = (a); i >= (b); --i) #define clr(x) memset(x,0,sizeof(x)) #define clrs( x , y ) memset(x,y,sizeof(x)) #define out(x) printf(#x" %d\n", x) #define sqr(x) ((x) * (x)) typedef long long LL; const int INF = 1000000000; const double eps = 1e-8; const int maxn = 30000; int sgn(const double &x) { return (x > eps) - (x < -eps); } int num[40]; map<string,int> m; map<int,string> mp; void init() { m["1m"]=1;m["2m"]=2;m["3m"]=3; m["4m"]=4;m["5m"]=5;m["6m"]=6; m["7m"]=7;m["8m"]=8;m["9m"]=9; m["1s"]=10;m["2s"]=11;m["3s"]=12; m["4s"]=13;m["5s"]=14;m["6s"]=15; m["7s"]=16;m["8s"]=17;m["9s"]=18; m["1p"]=19;m["2p"]=20;m["3p"]=21; m["4p"]=22;m["5p"]=23;m["6p"]=24; m["7p"]=25;m["8p"]=26;m["9p"]=27; m["1c"]=28;m["2c"]=29;m["3c"]=30; m["4c"]=31;m["5c"]=32;m["6c"]=33; m["7c"]=34; mp[0] = "1m";mp[1] = "2m";mp[2] = "3m"; mp[3] = "4m";mp[4] = "5m";mp[5] = "6m"; mp[6] = "7m";mp[7] = "8m";mp[8] = "9m"; mp[9] = "1s";mp[10] = "2s";mp[11] = "3s"; mp[12] = "4s";mp[13] = "5s";mp[14] = "6s"; mp[15] = "7s";mp[16] = "8s";mp[17] = "9s"; mp[18] = "1p";mp[19] = "2p";mp[20] = "3p"; mp[21] = "4p";mp[22] = "5p";mp[23] = "6p"; mp[24] = "7p";mp[25] = "8p";mp[26] = "9p"; mp[27] = "1c";mp[28] = "2c";mp[29] = "3c"; mp[30] = "4c";mp[31] = "5c";mp[32] = "6c"; mp[33] = "7c"; } int flag; bool ok(int x) { if(x >= 1 && x <= 7) return true; if(x >= 10 && x <= 16) return true; if(x >= 19 && x <= 25) return true; return false; } void dfs(int num_mj,int num_3,int num_2) { if(flag) return ; if(num_3 > 4 || num_2 > 1) return ; if(num_mj == 14) { if(num_3 == 4 && num_2 == 1) { flag = 1; } return; } repf(i,1,34) { int tag = 0; if(num[i] >= 3) { tag = 1; num[i] -= 3; dfs(num_mj + 3,num_3+1,num_2); num[i] += 3; } if(num[i]>=2) { tag = 1; num[i] -= 2; dfs(num_mj + 2,num_3,num_2+1); num[i] += 2; } if(ok(i) && num[i]>=1 && num[i+2]>=1&& num[i+1]>=1) { tag = 1; num[i]--; num[i+2]--; num[i+1]--; dfs(num_mj + 3,num_3+1,num_2); num[i]++; num[i+2]++; num[i+1]++; } if(num[i]) return; } } int tmp[13]={1,9,10,18,19,27,28,29,30,31,32,33,34}; bool judge7() { int num2 = 0; repf(i,1,34) if(num[i] == 2) num2++; return num2 == 7; } bool judge13() { int num2 = 0; int num1 = 0; rep(i,0,13) { if(num[tmp[i]] == 1) num1++; if(num[tmp[i]] == 2) num2++; } return num1==12 && num2 == 1; } int mj[20]; vector<string> ans; int main() { //freopen("in.txt","r",stdin); int T; scanf("%d",&T); init(); while(T--) { ans.clear(); rep(i,0,13) { string str; cin>>str; mj[i] = m[str]; } int tag = 0; repf(i,1,34) { clr(num); rep(j,0,13) num[mj[j]]++; if(num[i]>=4) continue; num[i]++; if(judge7()) { tag = 1; ans.push_back(mp[i-1]); num[i]--; continue; } if(judge13()) { tag = 1; ans.push_back(mp[i-1]); num[i]--; continue; } flag = 0; dfs(0,0,0); if(flag == 1) { tag = 1; ans.push_back(mp[i-1]); num[i]--; continue; } num[i]--; } if(tag == 0) cout<<"Nooten"<<endl; else { cout<<ans.size(); rep(i,0,ans.size()) cout<<" "<<ans[i]; cout<<endl; } } return 0; }
posted on 2013-10-20 18:04 keep trying 阅读(313) 评论(0) 编辑 收藏 举报