ZOJ3669: Japanese Mahjong I

Source: Internet
Author: User

MahjongIs a game of skill, strategy and calculation and involves a certain degree of chance. In this problem, we concentrate onJapanese Mahjong, A variation of mahjong. For brief, all of the wordMahjongMentioned following referJapanese Mahjong.

Japanese mahjong is usually played with 136 tiles, which can be Z done? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> v1_hbml6zwqgaw50bybzzxzlcmfsignhdgvnb3jpzxm6pc9wpgo8dww + Signature =" http://www.2cto.com/uploadfile/Collfiles/20140513/20140513090818326.jpg "alt =" \ ">BambooSuit
TheCharacterSuit
Honor tiles. Honor Tiles are tiles that do not have a rank or suit. they are divided into two categories. there are four types of Wind tiles and three types of Dragon tiles, with four of each type of honor tile. thus, there are 16 wind tiles and 12 Dragon tiles for 28 honor tiles.WindTiles. The Wind tiles consist of four kinds of tile:East,South,West, AndNorth.
DragonTiles. The Dragon titles consist of three types of tile:Red,Green,White.

AWinning handConsists of fourteen tiles, which is made of fourMelds(A specific pattern of three pieces) andEyes(A pair of two identical pieces). The definitionMeldsAndEyesIs given as followed:

    MeldsAre listed as followed: PongIs a set of three identical tiles. You can form a pong with any tile. The tiles must be identical (you cannot mix suits). For example:
    KongIs a set of four identical tiles, which is similar Pong. For example:
    ChowIs a meld of three suited tiles in sequence. the meld must be in absolute numerical sequence. there is no skipping of numbers, nor does 9 loop around to 1. the sequence must be in the same suit. honours cannot be used to make chows. for example:
    Eyes, Also known as a pair, are two identical tiles which are a component to the standard hand. For example:

    When a hand is one tile short of winning, the hand is said to beReady hand, Or more figuratively, "on the pot". The player holding a ready hand is said to beWaitingFor certain tiles. Now, given thirteen tiles, can you answer how many types of tiles you areWaitingForWinning hand? If the given hand were notReady hand, Output an integerZeroInstead.

    Input

    There are multiple cases. Each case consists of 26 characters in one line, describing thirteen tiles. The manner for describing each type of tile is:

      Two characters stand for one tile. Suited tiles, The first is a integer ranged from one to nine, the tile's rank, and the second is a character: 'P'For CircleSuit, 'S'For BambooSuit, and 'M'For CharacterSuit. Honor tiles, The first is a integer: from one to seven stands East, South, West, North, White, Green, And RedRespectively. The second one is always 'Z'. We promise that the input is a legal hand, which means there isn' t another type of tiles described above or there are more than four same tiles. Output

      For each case, first output the number of types of tiles you are waiting for in one line. then output each type of tile you are waiting for in the manner described above. output them in this fixed order: 'M', 'P', 's', 'z', and for each suit, smaller rank first (Honor tilesIs similarSuited tiles, Only using the integer standing for in abve manner instead of suited rank ).

      Sample Input
      1s1s1s2p3p4p6m7m8m1z1z1z2z1s1s1s2p3p4p6m7m8m1z1z1z9m1s1s1s2p3p4p6m7m8m1z1z1z1z1s2s3s1s2s3s2s3s7s8s9s6z6z
      Sample Output
      1 2z2 6m9m03 1s4s6z
      Hint
        The hand in the first picture is not Winning handIndeed, because there are already teen tiles. If 1 mOr 9 mIs droped, it will be Winning hand. Note that the input tiles is not ensured in the order of output.


        Question

        According to the requirements of one question, I can find out the cards


        # Include
            
             
        # Include
             
              
        # Include using namespace std; struct node {int num; char kind;} s [100000]; char str [100]; int a [4] [15]; int ta [4] [15]; int len, cnt; int find (int num) // find four {int I, j; if (num = 0) return 1; for (I = 0; I <4; I ++) // find three identical {for (j = 1; j <= 9; j ++) {if (a [I] [j] <3) continue; a [I] [j]-= 3; if (find (num-1) return 1; a [I] [j] + = 3 ;}}for (I = 0; I <3; I ++) // find a sentence {for (j = 1; j <= 7; j ++) {if (a [I] [j] & a [I] [j + 1] & & A [I] [j + 2]) {a [I] [j] --, a [I] [j + 1] --, a [I] [j + 2] --; if (find (num-1) return 1; a [I] [j] ++, a [I] [j + 1] ++, a [I] [j + 2] ++ ;}}return 0 ;}int solve () {int I, j; for (I = 0; I <4; I ++) {for (j = 1; j <= 9; j ++) {if (a [I] [j] <2) continue; if (I = 3 & j <= 7) {a [I] [j]-= 2; if (find (4) return 1; a [I] [j] + = 2;} else {a [I] [j]-= 2; if (find (4) return 1; a [I] [j] + = 2 ;}}return 0 ;}int main () {int I, j, k; while (~ Scanf ("% s", str) {cnt = 0; memset (a, 0, sizeof (a); for (I = 0; I <26; I + = 2) {if (str [I + 1] = 'M') a [0] [str [I]-'0'] ++; else if (str [I + 1] = 'P') a [1] [str [I]-'0'] ++; else if (str [I + 1] = 's') a [2] [str [I]-'0'] ++; else if (str [I + 1] = 'Z') a [3] [str [I]-'0'] ++ ;} char kind [5] = "mpsz"; for (I = 1; I <= 27 + 7; I ++) // enumerate all recognized cards {int id = (I-1)/9; int no = I % 9; if (no = 0) no = 9; memcpy (ta, a, sizeof (a); if (id <4 & a [id] [no] <4) // a [id] [no] ++; else continue; if (solve () {s [cnt] can be found only when there are fewer than four images. num = no; s [cnt]. kind = kind [id]; cnt ++;} memcpy (a, ta, sizeof (ta);} if (cnt = 0) {printf ("0 \ n"); continue;} printf ("% d", cnt); for (I = 0; I
              
               

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.