Mahjong Sorting

本文介绍了一个关于麻将牌排序的问题,其中涉及到特定规则和幸运牌的概念。给定一组已排序的麻将牌,任务是确定可能的幸运牌数量。题目提供多个测试用例,每个用例包含排序后的牌面信息,需要根据规则计算可能的幸运牌数目。代码示例展示了如何解析输入并计算答案。

链接:https://zoj.pintia.cn/problem-sets/91827364500/problems/91827370268

Time Limit: 1000 msMemory Limit: 65536 KB

DreamGrid has just found a set of Mahjong with  suited tiles and a White Dragon tile in his pocket. Each suited tile has a suit (Character, Bamboo or Dot) and a rank (ranging from 1 to ), and there is exactly one tile of each rank and suit combination.

Character tiles whose rank ranges from 1 to 9

Bamboo tiles whose rank ranges from 1 to 9

Dot tiles whose rank ranges from 1 to 9

White Dragon tile

As DreamGrid is bored, he decides to play with these tiles. He first selects one of the  suited tiles as the "lucky tile", then he picks  tiles from the set of  tiles and sorts these  tiles with the following rules:

  • The "lucky tile", if contained in the  tiles, must be placed in the leftmost position.

  • For two tiles  and  such that neither of them is the "lucky tile", if

    •  is a Character tile and  is a Bamboo tile, or

    •  is a Character tile and  is a Dot tile, or

    •  is a Bamboo tile and  is a Dot tile, or

    •  and  have the same suit and the rank of  is smaller than the rank of ,

    then  must be placed to the left of .

     

 

White Dragon tile is a special tile. If it's contained in the  tiles, it's considered as the original (not-lucky) version of the lucky tile during the sorting. For example, consider the following sorted tiles, where "3 Character" is selected as the lucky tile. White Dragon tile, in this case, is considered to be the original not-lucky version of "3 Character" and should be placed between "2 Character" and "4 Character".

As DreamGrid is quite forgetful, he immediately forgets what the lucky tile is after the sorting! Given  sorted tiles, please tell DreamGrid the number of possible lucky tiles.

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains two integers  and  (, ), indicating the number of sorted tiles and the maximum rank of suited tiles.

For the next  lines, the -th line describes the -th sorted tile counting from left to right. The line begins with a capital letter  (), indicating the suit of the -th tile:

  • If , then an integer  () follows, indicating that it's a Character tile with rank ;

  • If , then an integer  () follows, indicating that it's a Bamboo tile with rank ;

  • If , then an integer  () follows, indicating that it's a Dot tile with rank ;

  • If , then it's a White Drangon tile.

 

It's guaranteed that there exists at least one possible lucky tile, and the sum of  in all test cases doesn't exceed .

Output

For each test case output one line containing one integer, indicating the number of possible lucky tiles.

Sample Input

4
3 9
C 2
W
C 4
6 9
C 2
C 7
W
B 3
B 4
D 2
3 100
C 2
W
C 9
3 9
C 1
B 2
D 3

Sample Output

2
4
7
25

Hint

For the first sample, "2 Character" and "3 Character" are possible lucky tiles.

For the second sample, "8 Character", "9 Character", "1 Bamboo" and "2 Bamboo" are possible lucky tiles.

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=5e5+10;
long long mod=1e9;
char a[N][3];
int b[N],ans,flag,t,n,m;
void solve()
{
    if(flag==-1){
                        ans=m*3-n+1;
                    }
                    else if(flag==1){
                        if(a[2][0]=='C')ans=b[2]-1;
                        else if(a[2][0]=='B')ans=m+b[2]-1;
                        else ans=m*2+b[2]-1;
                    }
                    else if(n==2&&flag==2){
                        if(a[1][0]=='C')ans=m*3-b[1]+1;
                        else if(a[1][0]=='B')ans=m*2-b[1]+1;
                        else ans=m-b[1]+1;
                    }
                    else if(flag==n){
                        if(a[n-1][0]=='C')ans=m*3-b[n-1];
                        else if(a[n-1][0]=='B')ans=m*2-b[n-1];
                        else ans=m-b[n-1];
                    }
                    else {
                        if(flag==2){
                            if(a[1][0]==a[3][0])ans=b[3]-b[1];
                            else if(a[1][0]=='C'&&a[3][0]=='D')ans=m*2+b[3]-b[1];
                            else ans=m+b[3]-b[1];
                        }
                        else {
                            int x=flag;
                            if(a[x-1][0]==a[x+1][0])ans=b[x+1]-b[x-1]-1;
                            else if(a[x-1][0]=='C'&&a[x+1][0]=='D')ans=m*2+b[x+1]-b[x-1]-1;
                            else ans=m+b[x+1]-b[x-1]-1;
                        }
                    }
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&n,&m);
        flag=-1;
        for(int i=1;i<=n;i++)
        {
            scanf("%s",a[i]);
            if(a[i][0]=='W')
            {
                flag=i;
            }
            else
            {
                scanf("%d",&b[i]);
            }
        }
        if(n==1){
            ans=m*3;
        }
        else
        {
            if(a[1][0]==a[2][0])
            {
                if(b[1]>b[2])
                {
                    ans=1;
                }
                else
                {
                    solve();
                }
            }
            else if(a[1][0]=='C')
            {
                if(a[2][0]=='W')
                {
                    if(n==2)
                    {
                        if(a[1][0]=='C')ans=m*3-b[1]+1;
                        else if(a[1][0]=='B')ans=m*2-b[1]+1;
                        else ans=m-b[1]+1;
                    }
                    else
                    {
                        if(a[3][0]=='C')
                        {
                            if(b[1]>b[3])
                                ans=1;
                            else
                            solve();
                        }
                        else
                            solve();
                    }
                }
                else
                {
                    solve();
                }
            }
            else if(a[1][0]=='B')
            {
                if(a[2][0]=='C')
                    ans=1;
                else if(a[2][0]=='W')
                {
                    if(n==2)
                    {
                        if(a[1][0]=='C')ans=m*3-b[1]+1;
                        else if(a[1][0]=='B')ans=m*2-b[1]+1;
                        else ans=m-b[1]+1;
                    }
                    else
                    {
                        if(a[3][0]=='C')
                            ans=1;
                        else if(a[3][0]=='B')
                        {
                            if(b[1]>b[3])
                                ans=1;
                            else
                            solve();
                        }
                        else
                            solve();
                    }
                }
                else
                {
                    solve();
                }
            }
            else
            {
                if(a[2][0]=='C'||a[2][0]=='B')
                    ans=1;
                else if(a[2][0]=='W')
                {
                    if(n==2)
                    {
                        if(a[1][0]=='C')ans=m*3-b[1]+1;
                        else if(a[1][0]=='B')ans=m*2-b[1]+1;
                        else ans=m-b[1]+1;
                    }
                    else
                    {
                        if(a[3][0]=='C'||a[3][0]=='B')
                            ans=1;
                        else if(a[3][0]=='D')
                        {
                            if(b[1]>b[3])
                                ans=1;
                            else
                            solve();
                        }
                        else
                            solve();
                    }
                }
                else
                {
                    solve();
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

### Mahjong Helper 麻将辅助工具及相关项目 Mahjong Helper 是一个开源项目,专注于为麻将玩家提供帮助和分析功能。其生态系统中包含多个相关项目,这些项目可以进一步扩展其功能并提升用户体验[^1]。 #### 1. Mahjong AI Mahjong AI 是基于 Mahjong Helper 开发的一个智能系统,主要用于自动分析玩家的手牌并提供决策建议。该工具通过复杂的算法模拟对手的行为,并预测可能的出牌策略,从而帮助用户在游戏中做出更明智的选择[^1]。 #### 2. Mahjong Scoreboard Mahjong Scoreboard 是一个记录和展示比赛得分的工具,能够与 Mahjong Helper 无缝配合使用。它支持多种计分规则,并允许用户自定义比赛设置。通过实时更新比分信息,Mahjong Scoreboard 可以让玩家更加专注于游戏本身,而无需担心繁琐的分数计算问题[^1]。 #### 3. Mahjong Rules Mahjong Rules 是一个详细记录各种麻将规则的仓库,旨在为 Mahjong Helper 提供全面的规则支持。无论是传统中国麻将还是日式立直麻将,该项目都涵盖了丰富的规则说明和示例代码,确保用户能够在不同规则下正确使用 Mahjong Helper[^1]。 #### 4. Mahjong Helper - Majsoul 助手 对于《雀魂Majsoul》的爱好者而言,Mahjong Helper - Majsoul 助手是一个不可或缺的工具。它不仅可以帮助初学者快速掌握游戏技巧,还能为高级玩家提供深入的数据分析和策略优化建议。这款工具极大地提升了用户的竞技乐趣和游戏体验[^2]。 #### 5. Akagi 项目 Akagi 是另一个与麻将相关的项目,主要功能是通过拦截和解析《雀魂Majsoul》的游戏数据来实现自动化操作。在 `settings.json` 文件中,用户可以配置多个参数,例如是否启用自动播放(Autoplay)、是否使用 mahjong-helper(Helper)、以及是否自动和牌(Autohu)。此外,Akagi 还支持 MITM 端口重定向和 XMLRPC 端口绑定等功能,为开发者提供了更大的灵活性[^3]。 ```python # 示例:Akagi 的 settings.json 配置文件 { "Unlocker": true, "Autoplay": false, "Helper": true, "Autohu": true, "Port": 8080, "XMLRPC": 9090, "Playwright": { "viewport": { "width": 1920, "height": 1080 } } } ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值