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.