您的位置:首页 > 其它

HDU 4431 Mahjong(天津赛区亚洲区) 模拟题,方法很重要

2016-07-25 19:33 375 查看
Mahjong

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

Total Submission(s): 4797 Accepted Submission(s): 973

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

题意就是模拟麻将让你判断是否能胡牌。

比赛的时候没做出来,结束后想到了原来方法错了,导致这题在比赛中没有做出来。还有就是模拟题一定要注意细节,各种细节的成败决定了一切。

思路就是 给你13张牌后用map映射为整数,之后枚举每张牌,这样当你有14张牌的时候在判断是否胡牌就行了,

判断的方法题意说的很明确,有3种方式。

#include <stdio.h>
#include <map>
#include <algorithm>
#include <string.h>
#include <iostream>
#define maxs 40
#define MME(i,j) memset(i,j,sizeof(i))
using namespace std;
int cnt[140];
int ans[160];
int pos;
map<string,int>mp;
void init()
{
mp["1m"]=1; mp["1s"]=11; mp["1p"]=21;
mp["2m"]=2; mp["2s"]=12; mp["2p"]=22;
mp["3m"]=3; mp["3s"]=13; mp["3p"]=23;
mp["4m"]=4; mp["4s"]=14; mp["4p"]=24;
mp["5m"]=5; mp["5s"]=15; mp["5p"]=25;
mp["6m"]=6; mp["6s"]=16; mp["6p"]=26;
mp["7m"]=7; mp["7s"]=17; mp["7p"]=27;
mp["8m"]=8; mp["8s"]=18; mp["8p"]=28;
mp["9m"]=9; mp["9s"]=19; mp["9p"]=29;

mp["1c"]=31;mp["2c"]=32; mp["3c"]=33;
mp["4c"]=34;mp["5c"]=35; mp["6c"]=36;
mp["7c"]=37;
}

bool ok()
{
for(int i=1; i<38; i++)
{
if(cnt[i]>4)
return false;
}
return true;
}

bool judge()
{
int temp[40];
for(int i=1;i<38;i++)
temp[i]=cnt[i];

for(int i=1;i<38;i++)
{
if(temp[i]>=3)
temp[i]-=3;
if(temp[i])
{
if(i>30) return 0;
if(temp[i+1]<temp[i]||temp[i+2]<temp[i])
return false;
else
{
temp[i+1]-=temp[i];
temp[i+2]-=temp[i];
temp[i]=0;
}
}
}
return 1;
}

bool judge1() //判断 7个对
{
int tot=0;
for(int i=1;i<38;i++)
{
if(cnt[i]==2)
tot++;
}
if(tot==7)
return 1;
return 0;
}

bool judge2()//一个做眼的情况
{
bool flag=0;

for(int i=1;i<38;i++)
{
if(cnt[i]>=2)
{
cnt[i]-=2;
if(judge())
{
cnt[i]+=2;
return 1;
}
cnt[i]+=2;
}
}
return 0;
}

bool judge3()//东南西北那种情况
{
int special=0,other=0;
for(int i=0;i<3;i++)
{
if(cnt[i*10+9]==1)other++;
if(cnt[i*10+1]==1)other++;
if(cnt[i*10+1]==2)special++;
if(cnt[i*10+9]==2)special++;
}

for(int i=31;i<38;i++)
{
if(cnt[i]==1)   other++;
if(cnt[i]==2)   special++;
}

return (other==12&&special==1);
}
void work()
{
char s[40];
for(int i=0; i<13; i++)
{
scanf("%s",s);
cnt[mp[s]]++;
}

pos=0;
for(int i=1; i<38; i++)
{
if(i%10!=0)
{
cnt[i]++;
if(ok())
{
if(judge1()||judge2()||judge3())
{
ans[pos++]=i;
}
}
cnt[i]--;
}
}
if(pos)
{
printf("%d",pos);
for(int i=0;i<pos;i++)
{
printf(" %d",ans[i]%10);
if(ans[i]<10)
printf("m");
else if(ans[i]<20)
printf("s");
else if(ans[i]<30)
printf("p");
else printf("c");
}
printf("\n");
}
else printf("Nooten\n");
}

int main()
{
init();
long long  t;
scanf("%lld",&t);
while(t--)
{
MME(cnt,0);
MME(ans,0);
work();
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  HDU 亚洲区