QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 1024 MB 总分: 100

#7553. HackShuffle

统计

以下是针对该问题的翻译:

下面的类 Python 伪代码函数 HackShuffle() 接收一个正整数列表,以特定方式对列表中的整数进行洗牌,并返回结果列表。

下面使用了三个特定的函数。对于列表 L,函数 len(L) 返回 L 中元素的数量。方法 L.append(x) 将元素 x 添加到 L 的末尾。方法 L.pop(idx) 从列表 L 中移除指定位置 idx(从零开始计数)处的元素,并返回被移除的元素。

给定一个正整数列表 T,编写一个程序来重构列表 S,使得 T = HackShuffle(S)

function HackShuffle( Beta ):
if len( Beta ) <= 4 :
exit("Too small Beta")
Alpha = [] # [] is an empty list
Gamma = 0
Delta = len( Beta )
while( Delta >= 2 ) :
Omega = Beta[ Gamma ]
Alpha.append( Omega )
Beta.pop( Gamma )
Delta = Delta - 1
Gamma = ( Omega + Gamma - 1 ) % Delta
# end of while
Alpha.append( Beta[ 0 ] )
Pi = len( Alpha ) - 1
Omicron = Alpha[ Pi ]
Lambda = Alpha[ 0 ]
Rho = Omicron % Pi
Mu = Alpha[ Rho ]
Alpha[ 0 ] = Mu
Alpha[ Rho ] = Lambda
return ( Alpha )
# end of function HackShuffle

输入格式

第一行包含一个整数 $n$ ($5 \le n \le 200\,000$),即列表 T 的长度。

接下来的 $n$ 行,每行包含一个整数 $T_0, T_1, \dots, T_{n-1}$:即由 HackShuffle(S) 返回的列表 T ($1 \le T_i \le 100\,000$)。

输出格式

输出 $n$ 行,每行包含一个整数 $S_0, S_1, \dots, S_{n-1}$,其中 S 是满足 T = HackShuffle(S) 的列表。

样例

样例输入 1

13
113
49
68
91
10
179
2
71
78
45
57
10
88

样例输出 1

10
113
179
68
57
45
10
2
88
71
49
78
91

样例输入 2

9
6
8
7
9
5
1
2
4
3

样例输出 2

9
8
7
6
5
1
2
3
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.