QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 64 MB مجموع النقاط: 100

#23759. 카드 섞기

الإحصائيات

$1$부터 $2n$까지의 수가 적힌 $2n$장의 카드가 있으며, 위에서부터 $1, 2, 3, \ldots, 2n$의 순서로 쌓여 있다.

이 카드를 다음 방법을 몇 번 사용하여 재배열한다.

정수 $k$로 컷

위에서부터 $k$장의 카드 더미 A와 나머지 $2n-k$장의 카드 더미 B로 나눈 후, 더미 A 위에 더미 B를 올려놓는다.

problem_23759_23aef3360de866e41647ebc46ea8acfd.png

리플 셔플

위에서부터 $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.