CF1191B.Tokitsukaze and Mahjong

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 11 to 99). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …\ldots, 9m, 1p, 2p, …\ldots, 9p, 1s, 2s, …\ldots, 9s.

In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.

Do you know the minimum number of extra suited tiles she needs to draw so that she can win?

Here are some useful definitions in this game:

  • A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
  • A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;
  • A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.

Some examples:

  • [2m, 3p, 2s, 4m, 1s, 2s, 4s] — it contains no koutsu or shuntsu, so it includes no mentsu;
  • [4s, 3m, 3p, 4s, 5p, 4s, 5p] — it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;
  • [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] — it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.

Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.

tokitsukaze 正在玩一款源自日本麻将的游戏。在此游戏中,她手中有三张牌。她所拥有的每张牌均为“数牌”(suited tile),即每张牌既有花色(万子 manzu、筒子 pinzu 或索子 souzu),也有一个数字(取值范围为 11 到 99 的数字)。在本题中,我们使用一个数字加一个小写字母(该字母为花色名称的首字母)来表示一张数牌。所有可能的数牌表示为:1m、2m、…\ldots、9m、1p、2p、…\ldots、9p、1s、2s、…\ldots、9s。

为了赢得游戏,她手中必须至少包含一个“面子”(mentsu,定义见下文),因此有时她需要额外抽取数牌。每次抽牌后,她手中的牌数增加一张。她可以抽取任意数牌(包括手中已有的牌)。

你知道她为获胜所需抽取的最少额外数牌数量是多少吗?

以下是本游戏中一些重要的定义:

  • 一个“面子”(mentsu),亦称“组”(meld),由一个“刻子”(koutsu)或一个“顺子”(shuntsu)构成;
  • 一个“刻子”(koutsu),亦称“刻”(triplet),由三张完全相同的牌组成,例如 [1m, 1m, 1m];但 [1m, 1p, 1s] 或 [1m, 4m, 7m] 不是刻子;
  • 一个“顺子”(shuntsu),亦称“顺”(sequence),由同一花色中三个数字连续的牌组成,例如 [1m, 2m, 3m] 和 [5s, 7s, 6s];但 [9m, 1m, 2m](因 9、1、2 不构成连续数字)或 [1m, 2p, 3s](因花色不同)不是顺子。

一些例子:

  • [2m, 3p, 2s, 4m, 1s, 2s, 4s] —— 其中不包含任何刻子或顺子,因此不包含面子;
  • [4s, 3m, 3p, 4s, 5p, 4s, 5p] —— 其中包含一个刻子 [4s, 4s, 4s],但无顺子,因此包含面子;
  • [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] —— 其中不包含刻子,但包含一个顺子 [5p, 4p, 6p] 或 [5p, 7p, 6p],因此包含面子。

注意:牌的排列顺序无关紧要;且可假定每种数牌的供应数量是无限的。

输入格式

The only line contains three strings — the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from 11 to 99 and the second character is m, p or s.

唯一的一行包含三个字符串——即 Tokitsukaze 手中的牌。对每个字符串,第一个字符是范围在 11 到 99 之间的数字,第二个字符是 m、p 或 s。

输出格式

Print a single integer — the minimum number of extra suited tiles she needs to draw.

输出一个整数——她需要额外抽取的合适牌的最小数量。

输入输出样例

  • 输入#1

    1s 2s 3s

    输出#1

    0
  • 输入#2

    9m 9m 9m

    输出#2

    0
  • 输入#3

    3p 9m 2p

    输出#3

    1

说明/提示

In the first example, Tokitsukaze already has a shuntsu.

In the second example, Tokitsukaze already has a koutsu.

In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].

在第一个例子中,时雨已经拥有一个顺子。

在第二个例子中,时雨已经拥有一个刻子。

在第三个例子中,时雨可以通过摸一张花色牌(1p 或 4p)来组成一个顺子。最终的手牌将为
[3p, 9m, 2p, 1p] 或 [3p, 9m, 2p, 4p]。

输入解题思路,AI测评打分。不知道怎么写?

首页