QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 2048 MB Total points: 100

#8773. 魔豆

Statistics

“Magic Bean” 是一种组合益智玩具,包含 30 颗在三个圆形轨道上移动的彩色珠子。在复原状态下,上方圆圈包含 10 颗无法区分的橙色珠子,左下圆圈包含 10 颗无法区分的灰色珠子,右下圆圈包含 10 颗无法区分的红色珠子。每个圆圈中的珠子都可以旋转。此外,中间还有一个可以旋转的第四个圆圈,旋转它会交换各圆圈之间连续的三颗珠子。

你的兄弟借走了你的 Magic Bean 并随意旋转了这些圆圈,打乱了珠子的顺序。你的任务是通过找到一系列有效的圆圈旋转操作,将拼图恢复到复原状态。你不必找到最短的解法,但你的解法使用的步数不得超过 240 步。提供的输入是拼图在经过最多 240 步操作后的状态。

输入格式

输入包含三行。每行包含一个长度为 10 的字符串,仅由字符 'o'、'g' 和 'r' 组成。第一行描述上方圆圈中的 10 颗珠子,第二行描述左下圆圈中的珠子,第三行描述右下圆圈中的珠子。

字符 'o' 代表橙色珠子,'g' 代表灰色珠子,'r' 代表红色珠子。珠子按顺时针方向列出,编号如图所示。

输入配置是对复原状态的拼图执行最多 240 步操作后的结果。

输出格式

输出一个整数 $k$($0 \le k \le 240$),表示你复原拼图所需的步数。

如果 $k > 0$,则在接下来的 $k$ 行中输出这 $k$ 步操作,每行一步。每步操作由一个字符组成,指定要旋转的圆圈,紧随其后的是一个数字,指定圆圈顺时针旋转的幅度。上方圆圈用 'o' 表示,左下圆圈用 'g' 表示,右下圆圈用 'r' 表示,中心圆圈用 'c' 表示。对于前三个圆圈,旋转幅度的数字取值为 1 到 9;对于中心圆圈,取值为 1 到 2。

下图展示了两个样例的输入位置。

样例

样例输入 1

gggooooooo
rrrggggggg
ooorrrrrrr

样例输出 1

1
c2

样例输入 2

ggooooooog
rrrggggggg
ooorrrrrrr

样例输出 2

2
o1
c2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.