Mahjong
Time Limit: 4000/2000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 648 accepted submission (s): 111
Problem descriptionjapanese 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 1 m to 9 m to represent;
One to nine sou, which we use 1 s to 9 s to represent;
One to nine pin, which we use 1 p to 9 p 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 (1 m, 1 m, 1 m or 2C, 2c, 2C for example) or three continuous non-character tiles (1 m, 2 m, 3 M or 5S, 6 s, 7 S 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: 1 m, 9 m, 1 P, 9 P, 1 s, 9 s and all 7 character tiles. and the rest tile shoshould also be one of the 13 tiles above.
And the game starts with four players starting ing 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 shoshould 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 .)
Inputthe 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 abve.
Outputfor 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 input2 1 S 2 S 3 s 2C 2C 2 P 3 P 5 M 6 M 7 m 1 P 1 P 1 P 1 P 2 P 3 P 4S 6 s 7C 7C 3 S 3 S 2 M 2 m
Sample output2 1 P 4 P nooten
Source2012 Asia Tianjin Regional Contest
Recommendzhoujiaqi2010
Interesting questions.
That is, 13 cards are given. Ask which cards can be added.
Hu Pai has the following situations:
1. One pair + four groups of three identical cards or shunzi. Only M, S, and P can constitute a subfolder. Brands like East and West are not good.
2. Seven different pairs.
3. 1 m, 9 m, 1 P, 9 P, 1 s, 9 s, 1C, 2c, 3c, 4C, 5C, 6C, 7c. each of these 13 cards has only these 13 cards. There must be two. The other one.
The first is to enumerate 18 + 7 = 34 cards and add 14 cards to determine the cards.
Hu Pai's judgment is as follows.
In the first case, enumerate each pair. Then, search for three identical or shunzi images in sequence. If there are three identical sheets, they constitute three identical sheets. If you don't have it, you can see whether it can make up with the following. Be sure to search in ascending order. 1c ''' 7C can only make up three identical images. Then determine if exactly four groups are found.
In the second case, the number of each card is either 0 or 2, which must be seven different pairs.
The third case is to make the number of the 13 cards not equal to 0, and the number of other cards is 0;
This is a good practice that fox reminds me.
# Include <stdio. h> # Include <Iostream> # Include < String . H> # Include <Algorithm> Using Namespace STD; Int CNT [ 35 ]; Bool Judge4x3 (){ Int Ret = 0 ; Int TMP [ 35 ]; For ( Int I = 0 ; I < 34 ; I ++) TMP [I] = CNT [I]; For ( Int I = 0 ; I <= 18 ; I + =9 ) For ( Int J = 0 ; J < 9 ; J ++ ){ If (TMP [I + J]> = 3 ) {TMP [I + J]-= 3 ; RET ++ ;} While (J +2 < 9 & TMP [I + J] & TMP [I + J + 1 ] & TMP [I + J + 2 ]) {TMP [I + J] -- ; TMP [I + J + 1 ] -- ; TMP [I + J + 2 ] -- ; RET ++ ;}} For (Int J = 0 ; J < 7 ; J ++ ){ If (TMP [ 27 + J]> = 3 ) {TMP [ 27 + J]-= 3 ; RET ++ ;}} If (Ret = 4 )Return True ; Return False ;} Bool Judge1 (){ For ( Int I = 0 ; I < 34 ; I ++ ){ If (CNT [I]> = 2 ) {CNT [I] -= 2 ; // Enumeration child If (Judge4x3 () {CNT [I] + = 2 ; Return True ;} CNT [I] + = 2 ;}} Return False ;} Bool Judge2 (){ For ( Int I = 0 ; I < 34 ; I ++ ){ If (CNT [I]! = 2 & CNT [I]! = 0 ) Return False ;} Return True ;} Bool Judge3 (){ For ( Int J = 0 ; J < 7 ; J ++ ) If (CNT [J + 27 ] = 0 ) Return False ; For ( Int I = 0 ; I <= 18 ; I + = 9 ){ If (CNT [I] = 0 | CNT [I + 8 ] = 0 ) Return False ; For ( Int J = 1 ; J < 8 ; J ++ ) If (CNT [I + J]! = 0 ) Return False ;} Return True ;} Bool Judge (){ If (Judge1 () | judge2 () | judge3 ()) Return True ; Return False ;} Int Main (){ Int T; Char STR [ 10 ]; Scanf ( " % D " ,& T ); Int Ans [ 35 ], Tol; While (T -- ) {Memset (CNT, 0 , Sizeof (CNT )); For ( Int I = 0 ; I < 13 ; I ++ ) {Scanf ( " % S " ,& Str ); Int T = STR [ 0 ]- ' 1 ' ; If (STR [ 1 ] = ' M ' ) T + = 0 ; Else If (STR [ 1 ] = ' S ' ) T + = 9 ; Else If (STR [ 1 ] = ' P ' ) T + = 18 ; Else T + = 27 ; CNT [T] ++ ;} Tol = 0 ; For ( Int I = 0 ; I < 34 ; I ++ ) {CNT [I] ++; If (CNT [I] <= 4 && Judge () ans [Tol ++] = I; CNT [I] -- ;} If (Tol = 0 ) Printf ( " Nooten \ n " ); Else {Printf ( " % D " , Tol ); For ( Int I = 0 ; I <tol; I ++ ) {Printf ( " % D " , (ANS [I] % 9 ) + 1 ); If (ANS [I]/9 = 0 ) Printf ( " M " ); Else If (ANS [I]/ 9 = 1 ) Printf ( " S " ); Else If (ANS [I]/ 9 = 2 ) Printf ( " P " ); Else Printf ( " C " );} Printf ( " \ N " );}} Return 0 ;}