QOJ.ac

QOJ

时间限制: 1 s 内存限制: 2048 MB 总分: 100

#7665. 行李

统计

一家航空公司有两架航班几乎同时从 ICPCity 出发,一架飞往 B 城,另一架飞往 A 城。航空公司有 $n$ 个柜台供乘客托运行李。每个柜台都有一对相同的行李箱,一个属于 B 城,另一个属于 A 城。

在航班起飞前,每一对行李箱都会由一辆电动搬运车移动到分拣区。搬运车每次总是移动两个箱子,一个属于 B 城,另一个属于 A 城。当所有箱子都被移动后,它们在分拣区排成如下队列:

B A B A B A ... B A

也就是说,共有 $2n$ 个行李箱排成一行,第一个是 B 城箱子,第二个是 A 城箱子,以此类推。现在的任务是重新排列它们,使得所有 A 城箱子都排在所有 B 城箱子之前,这样箱子就可以被装载到相应的飞机上。

重新排列是通过移动相邻的一对行李箱(不一定是 B 在前 A 在后)来完成的,同样使用电动搬运车。为了保持平衡,搬运车必须始终携带两个箱子,绝不能只携带一个。一对箱子必须始终移动到一个至少有两个箱子宽度的空位中。在第一个箱子的左侧有一些空位,可以在重新排列过程中根据需要使用。

当重新排列过程开始时,箱子的位置编号从 $1$(最初放置最左侧的 B 城行李箱)到 $2n$(最初放置最右侧的 A 城行李箱)。在箱子左侧有 $2n$ 个初始为空的位置,编号从 $0$ 到 $-2n+1$,如图 A.1 所示(以 $n=4$ 为例)。

图 A.1:$n=4$ 时箱子和空位的初始配置

给定 $n$,求出一个最短的移动序列,将箱子重新排列,使得所有 A 城箱子都在所有 B 城箱子左侧。在过程结束时,最左侧的 A 城箱子可能位于 $1$ 以外的位置,但所有箱子必须在 $2n$ 个连续的位置上保持相邻。

输入格式

输入包含单个测试用例,由整数 $n$ ($3 \le n \le 100$) 组成。

输出格式

输出一个最短的移动序列,使箱子正确重新排列。每次移动的形式为 “$f$ to $t$”,其中 $f$ 和 $t$ 是整数,表示将位于位置 $f$ 和 $f+1$ 的箱子移动到位置 $t$ 和 $t+1$。如果存在多种方案,输出其中任意一种即可。

样例

样例输入 1

5

样例输出 1

8 to -1
3 to 8
6 to 3
0 to 6
9 to 0

样例输入 2

8

样例输出 2

10 to -1
3 to 10
14 to 3
7 to 14
0 to 7
11 to 0
4 to 11
15 to 4

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.