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.