当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5338:ZZX and Permutations

题目描述
ZZX likes permutations.

ZZX knows that a permutation can be decomposed into disjoint cycles(see https://en.wikipedia.org/wiki/Permutation#Cycle_notation). For example:
145632=(1)(35)(462)=(462)(1)(35)=(35)(1)(462)=(246)(1)(53)=(624)(1)(53)……
Note that there are many ways to rewrite it, but they are all equivalent.
A cycle with only one element is also written in the decomposition, like (1) in the example above.

Now, we remove all the parentheses in the decomposition. So the decomposition of 145632 can be 135462,462135,351462,246153,624153……

Now you are given the decomposition of a permutation after removing all the parentheses (itself is also a permutation). You should recover the original permutation. There are many ways to recover, so you should find the one with largest lexicographic order.
输入解释
First line contains an integer $t$, the number of test cases.
Then $t$ testcases follow. In each testcase:
First line contains an integer $n$, the size of the permutation.
Second line contains $n$ space-separated integers, the decomposition after removing parentheses.

$n\le 10^5$. There are 10 testcases satisfying $n\le 10^5$, 200 testcases satisfying $n\le 1000$.
输出解释
Output $n$ space-separated numbers in a line for each testcase.
Don't output space after the last number of a line.
输入样例
2
6
1 4 5 6 3 2
2
1 2
输出样例
4 6 2 5 1 3
2 1
来自杭电HDUOJ的附加信息
Author XJZX
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5338

最后修改于 2020-10-25T23:21:49+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
6000/3000MS(Java/Others) 131072/131072K(Java/Others)