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

建议使用的浏览器:

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

4713:Permutation

题目描述
A permutation of n elements is a one-to-one function (injection) p: {1,2,...,n} -> {1,2,...,n}. An order of permutation p is the minimal k >= 1, such that for all i=1,2,...,n we have:
p(p(....p(i)...)) = i

That is, p composed with itself k times becomes identity function. For example, the order of the permutation of 3 elements p(1)=3, p(2)=2, p(3)=1 is 2, because p(p(1))=1, p(p(2))=2, p(p(3))=3.
For a given n let us consider permutations of n-elements having the the largest order possible. For example, the maximal order of a permutation of 5 elements is 6. An example of a permutation of 5 elements whose order is 6 is p(1)=4, p(2)=5, p(3)=2, p(4)=1, p(5)=3.
Among all permutations of n elements having the maximal order, we would like to find the earliest one (in a lexycographic order). Being more precise, we say a permutation p of n elements is earlier than a permutation r of n elements, if there is i, such that p(j) = r(j) for all j < i and p(i) < r(i). The earliest permutation of 5 elements having an order 6 is p(1)=2,p(2)=1,p(3)=4,p(4)=5,p(5)=3.
输入解释
There is one positive integer t (1 <= t <= 30) in the first line of the standard input. In the following T lines there are positive integers N1, N2, ..., Nt, one per line, 1 <= ni <= 10000.
输出解释
Your programme should write t lines to the standard output. The ith line should contain a sequence of integers separated by spaces, forming the least permutation of ni elements having the maximal order, i.e. the sequence p(1), p(2), ..., p(Ni), where p denotes this permutation.
输入样例
2
5
14
输出样例
2 1 4 5 3
2 3 1 5 6 7 4 9 10 11 12 13 14 8
来自杭电HDUOJ的附加信息
Recommend liuyiding

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

源链接: HDU-4713

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

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 102400/102400K(Java/Others)