#1403. [ACSL23-24 Junior] Tiles

[ACSL23-24 Junior] Tiles

问题描述

ACSL Tiles 是一个与长方形图块有关的单人游戏。每个图块的两端都有一个位于 1 ~ 9 之间(包括1 和 9)的个位数。游戏开始时,共 4 行,每一行都包含一个数字。游戏目标是构建行,将一个图块放在最顶层一行的右端,使得这行的最后一个数字与图块上的一个数字匹配。图块可以改变方向;例如,图块 34 和图块 43 相同。如果一个图块不能放置在任何一行中,则放弃该图块并将其归入discard pile。当所有图块都已放置或放弃时,求discard pile 中所有图块上个位数的总和。

英文描述 - 注意,原题为英文,中文试题翻译有歧义

ACSL Tiles is a one-person game played with rectangular tiles. Each tile has a single-digit number between 1 and 9 inclusive at each end. At the start of the game, there are 4 rows, each with a number. The goal of the game is to build rows by placing a tile at the right end of the topmost row whose last number matches a number on the tile. Tiles can be re-oriented; thus, the tiles 34 and 43 are the same tile. If a tile cannot be placed on any row, it is placed in the discard pile. When all tiles have been played or discarded, find the sum of the single-digit numbers on all of the tiles in the discard pile.

输入格式

输入一个 4 位数,这 4 位数字为第 1 行到第 4 行的初始数字, 后面跟着一串包含不超过 50 个的两位整数,数字之间用一个空格隔开。每个两位整数代表每个图块上两个位于1 - 9 之间(包括1 和9 )的数字。

输出格式

按照上述规则放置图块之后,输出discard pile 中所有图块上个位数的总和 。

示例

输入:

5923
56 85 27 73 14 34 62

输出:

18

详解:
游戏开始时,4 行初始数字为 5、9、2、3。

image

首先将图块56 放在第 1 行,然后图块85 归入discard pile 。图块 27 和 73 都放在第 3 行,图块14 归入discard pile。

image

接下来,将图块 34 放在第 3 行,而后返回第 1 行。最后,图块 26 旋转变成 62 后放在第1 行。结果如下:

image

加总可得:8+5+1+4=18。