QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 32 MB مجموع النقاط: 10

#11663. 游戏

الإحصائيات

棋盘由 $2n + 1$ 个编号的格子组成。共有 $n$ 个黑色棋子和 $n$ 个白色棋子。黑色棋子位于棋盘的前 $n$ 个格子(编号从 $1$ 到 $n$),而白色棋子位于最后 $n$ 个格子(编号从 $n + 2$ 到 $2n + 1$)。初始时,只有第 $(n + 1)$ 个格子是空的。


a. $n = 3$ 时棋子的初始布局及棋子的可能移动方式
b. 将白色棋子从第 5 号格子移走后的棋盘及棋子的可能移动方式

在游戏过程中,可以执行两种类型的移动。第一种是平移,即将棋子移动到相邻的空位。第二种是跳跃,即跳过一个相邻的异色棋子并落在空位上。

游戏的目标是交换黑色棋子和白色棋子的位置。换句话说,黑色棋子必须移动到编号从 $n+2$ 到 $2n+1$ 的格子,而白色棋子应移动到编号从 $1$ 到 $n$ 的格子。请找出完成游戏目标的最短移动序列。

任务

编写一个程序,完成以下工作:

  • 读取一个整数 $n$,表示白色棋子和黑色棋子的数量;
  • 确定导致游戏目标的最短移动序列;
  • 输出答案。

输入格式

标准输入的第一行也是唯一一行包含一个整数 $n$ ($1 \le n \le 100$)。

输出格式

标准输出的第一行应包含一个整数 $m$,表示导致游戏目标的最短移动序列的长度。接下来的 $m$ 行,每行应包含一个范围在 $[1, 2n + 1]$ 之间的整数。第 $(i + 1)$ 行的整数(对于 $1 \le i \le m$)定义了第 $i$ 次移动中棋子所在的起始格子编号。

如果存在多种可能的解,程序可以输出其中任意一个。

样例

输入 1

1

输出 1

3
1
3
2

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.