QOJ.ac

QOJ

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

#7665. 行李

Statistics

某航空公司有兩班航班在差不多的時間從 ICPCity 起飛,一班前往城市 B,另一班前往城市 A。航空公司還有 $n$ 個供乘客託運行李的櫃檯。每個櫃檯都有一對相同的行李箱,一個供城市 B 使用,另一個供城市 A 使用。

航班即將起飛時,每一對行李箱都會由一輛電動搬運車運至分揀區。搬運車每次總是搬運兩個箱子,一個前往城市 B,另一個前往城市 A。所有箱子搬完後,它們在分揀區排成如下順序:

$$\mathrm{B\ A\ B\ A\ B\ A\ \ldots\ B\ A}$$

也就是說,一列共有 $2n$ 個行李箱,首先是前往城市 B 的箱子,再來是前往城市 A 的箱子,如此交替。現在的任務是重新排列,使所有前往城市 A 的行李箱都排在前往城市 B 的行李箱之前。之後即可將箱子裝上相應的飛機。

重新排列仍然使用電動搬運車,每次移動相鄰的兩個行李箱(不一定是 B 在前、A 在後)。為保持適當平衡,搬運車必須一直搬運兩個箱子,不能只搬一個。每對箱子必須移到至少有兩個箱子寬的空位。第一個箱子左側有一些空位,重新排列時可按需要使用。

開始重新排列時,箱子的位置從 $1$(最初放著最左邊的 B 行李箱)編號至 $2n$(最初放著最右邊的 A 行李箱)。箱子左側最初有 $2n$ 個空位,從 $0$ 編號至 $-2n+1$。圖 A.1 展示了 $n=4$ 的情況。

problem_7665_113d453aa04e914f3a265312f8ef181c.png

圖 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.