QOJ.ac

QOJ

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

#23759. 卡片洗牌

Statistics

有 $2n$ 張寫有從 $1$ 到 $2n$ 的數字的卡片,由上而下按 $1, 2, 3, \ldots, 2n$ 的順序疊放在一起。

多次使用以下方法對這些卡片進行重新排列:

以整數 $k$ 切牌

將牌堆分成由上往下前 $k$ 張卡片組成的牌堆 A 與由其餘 $2n-k$ 張卡片組成的牌堆 B 後,將牌堆 B 放在牌堆 A 的上面。

problem_23759_23aef3360de866e41647ebc46ea8acfd.png

交錯洗牌(Riffle shuffle)

將牌堆分成由上往下前 $n$ 張卡片組成的牌堆 A 與由其餘 $n$ 張卡片組成的牌堆 B,然後按由上而下依序為 A 的第 $1$ 張、B 的第 $1$ 張、A 的第 $2$ 張、B 的第 $2$ 張、$\ldots$、A 的第 $n$ 張、B 的第 $n$ 張的方式合併成 $1$ 個牌堆。

problem_23759_b7a05d9ba29945a1384455aee42f82a0.png

請撰寫一個程式,按照輸入中的指示重新排列卡片,並由上而下依序輸出重新排列後各張卡片上的編號。

輸入格式

  • 第 $1$ 行寫有 $n$($1 \le n \le 100$)。即卡片的張數為 $2n$ 張。
  • 第 $2$ 行寫有操作的次數 $m$($1 \le m \le 1000$)。
  • 從第 $3$ 行到第 $m + 2$ 行的 $m$ 行中,每行寫有從 $0$ 到 $2n-1$ 之間的 $1$ 個整數 $k$,依序指定重新排列卡片的方法:
    • 當 $k = 0$ 時,進行交錯洗牌。
    • 當 $1 \le k \le 2n-1$ 時,以 $k$ 進行切牌。

輸出格式

輸出由 $2n$ 行組成。在第 $1$ 行輸出重排結束後最上面那張卡片的編號,在第 $2$ 行輸出重排結束後由上往下第 $2$ 張卡片的編號,依此類推,在第 $i$ 行輸出由上往下第 $i$ 張卡片的編號。

範例

輸入格式 1

2
2
1
0

輸出格式 1

2
4
3
1

輸入格式 2

3
4
2
4
0
0

輸出格式 2

1
5
4
3
2
6

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.