ZOJ3669:Japanese Mahjong I

Mahjong is a game of skill, strategy and calculation and involves a certain degree of chance. In this problem, we concentrate on Japanese Mahjong, a variation of mahjong. For brief, all of the word mahjong mentioned
following refer to Japanese Mahjong.

Japanese mahjong is usually played with 136 tiles, which can be organized into several categories:

  • Suited tiles. All suited tiles are of a rank and a suit.There are three suits of tiles, with ranks ranging from one to nine. There are four tiles of each rank and suit combination, thus there are 36 tiles in a suit, and 108 suited tiles in total.

    • The circle suit

    • The bamboo suit

    • The character suit

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

    • Wind tiles. The Wind tiles consist of four kinds of tile: EastSouthWest, and North.

    • Dragon tiles. The Dragon titles consist of three types of tile: RedGreenWhite.

winning hand consists of fourteen tiles, which is made of four melds (a specific pattern of three pieces) and the eyes (a pair of two identical
pieces). The definition of melds and eyes is given as followed:

  • Melds are listed as followed:

    • Pong is 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:

    • Kong is a set of four identical tiles, which is similar to Pong. For example:

    • Chow is 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 be a ready hand, or more figuratively, "on the pot". The player holding a ready hand is said to be waiting for certain tiles.
Now, given thirteen tiles, can you answer how many types of tiles you are waiting for a winning hand? If the given hand were not a ready hand, output an integer zero instead.

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.
  • For Suited tiles, the first is a integer ranged from one to nine, the tile‘s rank, and the second is a character: ‘p‘ for the circle suit, ‘s‘ for
    the bamboo suit, and ‘m‘ for the character suit.
  • For Honor tiles, the first is a integer: from one to seven stands for EastSouthWestNorthWhiteGreen,
    and Red respectively. 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 tiles is similar to suited tiles, only using the integer standing for in above manner instead of suited rank).

Sample Input

1s1s1s2p3p4p6m7m8m1z1z1z2z
1s1s1s2p3p4p6m7m8m1z1z1z9m
1s1s1s2p3p4p6m7m8m1z1z1z1z
1s2s3s1s2s3s2s3s7s8s9s6z6z

Sample Output

1 2z
2 6m9m
0
3 1s4s6z

Hint

  • The hand in the first picture is not a winning hand indeed, because there are fifteen tiles. If 1m or 9m is droped, it will be a winning
    hand
    .
  • Note that the input tiles is not ensured in the order of output.

题意

按一题目的要求输出摸到那些牌能胡牌

#include <stdio.h>
#include <string.h>
#include <algorithm>
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)//找出4个三个一组的
{
    int i,j;
    if(num == 0) return 1;
    for(i = 0; i<4; i++)//找出三个一样的
    {
        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++)//找出一句话
    {
        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++)//枚举所有摸到的牌
        {
            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].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<cnt; i++)
            printf("%d%c",s[i].num,s[i].kind);
        printf("\n");

    }

    return 0;
}

ZOJ3669:Japanese Mahjong I,布布扣,bubuko.com

时间: 2024-10-13 12:27:17

ZOJ3669:Japanese Mahjong I的相关文章

ZOJ3671:Japanese Mahjong III

Mahjong is a game of skill, strategy and calculation and involves a certain degree of chance. In this problem, we concentrate on Japanese Mahjong, a variation of mahjong. For brief, all of the word mahjong mentioned following refer to Japanese Mahjon

ZOJ 3671 Japanese Mahjong III

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3671 Japanese Mahjong III Time Limit: 2 Seconds      Memory Limit: 65536 KB Mahjong is a game of skill, strategy and calculation and involves a certain degree of chance. In this proble

zoj 3669 Japanese Mahjong I

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3669 题目大意:就是给你一副牌,问你胡牌的方式有几种,并输出方式..... 思路:因为一副牌的数量不多,所以可以直接枚举每一张牌,判断加上这张牌后能否胡牌... code: #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #incl

HDU 4431 Mahjong (麻将、神坑模拟题)

题目链接: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): 4219    Accepted Submission(s): 842 Problem Description Japanese Mahjong is a fou

ZOJ Monthly, November 2012

A.ZOJ 3666 Alice and Bob 组合博弈,SG函数应用 #include<vector> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn = 10000 + 100; int SG[maxn]; vector<int> g[maxn]; int mex(int u) { //minimal exc

HDU-4431 麻将

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

hdu 5379 Mahjong tree(树形dp)

题目链接:hdu 5379 Mahjong tree 树形dp,每个节点最多有2个子节点为一棵节点数大于1的子树的根节点,而且要么后代的节点值都大于,要么都小于本身(所以tson不为0是,要乘2).对于K个单一节点的子节点,种类数即为全排K!.当一个节点没有兄弟节点时,以这个节点为根结点的子树,根可以选择最大或者最小. #pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #inclu

Mahjong tree (hdu 5379 dfs)

Mahjong tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 190    Accepted Submission(s): 58 Problem Description Little sun is an artist. Today he is playing mahjong alone. He suddenly feels

【HDOJ 5379】 Mahjong tree

[HDOJ 5379] Mahjong tree 往一颗树上标号 要求同一父亲节点的节点们标号连续 同一子树的节点们标号连续 问一共有几种标法 画了一画 发现标号有二叉树的感觉 初始标号1~n 根结点1可以标1或n 否则其他情况无法让下面的子树满足各自连续并且该根的儿子节点都要连续 根结点下的节点平分其他标号 画一画可以发现 每个根下最多有两颗子树 否则无法满足条件 并且两颗子树占据剩余标号的左右两边 中间夹的必须是叶子 这样才能满足该根下的儿子节点标号连续 若根下只有一颗子树 同样可以选择占剩