您的位置:首页 > 其它

hdu 4431 Mahjong (模拟)

2017-04-10 23:31 393 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4431


Mahjong

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 5090    Accepted Submission(s): 1043


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.)

 

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

2012 Asia Tianjin Regional Contest

 

Recommend

zhoujiaqi2010   |   We have carefully selected several similar problems for you:  6022 6021 6020 6019 6018 

题意:给你13张底牌,然后让你判断再起那张牌可以 “胡”, 就一直模拟 9 + 9 + 9 + 7 = 34 张牌,能胡的输出就行了,模拟完所有的牌不能 “胡”,就输出  Nooten  即可

解析:一共有三种胡牌的方法,

1    2张一样的 + 3(3张一样的, 或者是顺子,只能是 m  s  p)

2    7对(每对都不一样)

3    只能1m  9m  1s  9s 1p 9p 1c 2c 3c 4c 5c 6c 7c

借鉴大牛博客:http://www.cnblogs.com/kuangbin/archive/2012/10/27/2742985.html

本菜鸡今天WA了一天,刚把这道题AC了,就是判断情况时一直出错



代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<string>
#define N 1009
using namespace std;
const int INF = 0x3f3f3f3f;
int m[10], s[10], p[10], c[10], tmp[36];
char ans
;

bool judge1()
{
for(int i = 1; i <= 9; i++)
{
if((m[i] != 2 && m[i] != 0) || (s[i] != 2 && s[i] != 0) || (p[i] != 2 && p[i] != 0)) return false;
}
for(int i = 1; i <= 7; i++)
{
if(c[i] != 2 && c[i] != 0) return false;
}
return true;
}

bool judge2()
{
for(int i = 2; i <= 8; i++)
{
if(m[i] || s[i] || p[i]) return false;
}
if(!m[1] || !m[9] || !s[1] || !s[9] || !p[1] || !p[9]) return false;
for(int i = 1; i <= 7; i++)
{
if(!c[i]) return false;
}
return true;
}

bool judge3()
{
int rec = 0, tp[36];
memcpy(tp, tmp, sizeof(tmp));
for(int i = 1; i <= 27; i++)
{
if(tp[i] >= 3)
{
rec++;
tp[i] -= 3;
}
while(((i <= 7) || (i >= 10 && i <= 16) || (i >= 19 && i <= 25)) && tp[i] && tp[i + 1] && tp[i + 2])
{
rec++;
tp[i]--;
tp[i + 1]--;
tp[i + 2]--;
}
}
for(int i = 28; i <= 34; i++)
{
if(tp[i] >= 3)
{
rec++;
tp[i] -= 3;
}
}
return rec == 4;
}

bool check()
{
if(judge1()) return true;
if(judge2()) return true;

int cnt = 1;
for(int i = 1; i <= 9; i++) tmp[cnt++] = m[i];
for(int i = 1; i <= 9; i++) tmp[cnt++] = s[i];
for(int i = 1; i <= 9; i++) tmp[cnt++] = p[i];
for(int i = 1; i <= 7; i++) tmp[cnt++] = c[i];
for(int i = 1; i < cnt; i++)
{
if(tmp[i] >= 2)
{
tmp[i] -= 2;
if(judge3()) return true;
tmp[i] += 2;
}
}
return false;
}

int main()
{
int t, cnt;
char ch[3];
scanf("%d", &t);
while(t--)
{
cnt = 0;
memset(m, 0, sizeof(m));
memset(s, 0, sizeof(s));
memset(p, 0, sizeof(p));
memset(c, 0, sizeof(c));
for(int i = 1; i <= 13; i++)
{
scanf("%s", ch);
if(ch[1] == 'm') m[ch[0]-'0']++;
if(ch[1] == 's') s[ch[0]-'0']++;
if(ch[1] == 'p') p[ch[0]-'0']++;
if(ch[1] == 'c') c[ch[0]-'0']++;
}
for(int i = 1; i <= 9; i++)
{
m[i]++;
if(m[i] <= 4 && check()) ans[cnt++] = i + '0', ans[cnt++] = 'm';
m[i]--;
}
for(int i = 1; i <= 9; i++)
{
s[i]++;
if(s[i] <= 4 && check()) ans[cnt++] = i + '0', ans[cnt++] = 's';
s[i]--;
}
for(int i = 1; i <= 9; i++)
{
p[i]++;
if(p[i] <= 4 && check()) ans[cnt++] = i + '0', ans[cnt++] = 'p';
p[i]--;
}
for(int i = 1; i <= 7; i++)
{
c[i]++;
if(c[i] <= 4 && check()) ans[cnt++] = i + '0', ans[cnt++] = 'c';
c[i]--;
}
ans[cnt] = '\0';
int num = strlen(ans) / 2;
if(!num) puts("Nooten");
else
{
printf("%d", num);
for(int i = 0; ans[i]; i += 2)
{
printf(" %c%c", ans[i], ans[i + 1]);
}
printf("\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: