CF1930B.Permutation Printing
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a positive integer n.
Find a permutation† p of length n such that there do not exist two distinct indices i and j (1≤i,j<n; i=j) such that pi divides pj and pi+1 divides pj+1.
Refer to the Notes section for some examples.
Under the constraints of this problem, it can be proven that at least one p exists.
† A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
给你一个正整数 n。
请构造一个长度为 n 的排列† p,使得不存在两个互异的下标 i 和 j(满足 1≤i,j<n 且 i=j),使得 pi 整除 pj 且 pi+1 整除 pj+1。
有关示例,请参见“注意事项”部分。
在本题的约束条件下,可以证明至少存在一个满足条件的 p。
† 长度为 n 的排列是指由 1 到 n 中 n 个互不相同的整数以任意顺序组成的数组。例如,[2,3,1,5,4] 是一个排列,而 [1,2,2] 不是排列(数字 2 在数组中出现了两次),[1,3,4] 也不是排列(此时 n=3,但数组中包含了 4)。
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤103) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n (3≤n≤105) — the length of the permutation p.
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤103),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(3≤n≤105),表示排列 p 的长度。
保证所有测试用例的 n 之和不超过 105。
输出格式
For each test case, output p1,p2,…,pn.
If there are multiple solutions, you may output any one of them.
对于每个测试用例,输出 p1,p2,…,pn。
如果存在多个解,你可以输出其中任意一个。
输入输出样例
输入#1
2 4 3
输出#1
4 1 2 3 1 2 3
说明/提示
In the first test case, p=[4,1,2,3] is a valid permutation. However, the permutation p=[1,2,3,4] is not a valid permutation as we can choose i=1 and j=3. Then p1=1 divides p3=3 and p2=2 divides p4=4. Note that the permutation p=[3,4,2,1] is also not a valid permutation as we can choose i=3 and j=2. Then p3=2 divides p2=4 and p4=1 divides p3=2.
In the second test case, p=[1,2,3] is a valid permutation. In fact, all 6 permutations of length 3 are valid.
在第一个测试用例中,p=[4,1,2,3] 是一个合法的排列。然而,排列 p=[1,2,3,4] 并不合法,因为我们可以选择 i=1 和 j=3,此时 p1=1 整除 p3=3,且 p2=2 整除 p4=4。注意,排列 p=[3,4,2,1] 同样不合法,因为我们可以选择 i=3 和 j=2,此时 p3=2 整除 p2=4,且 p4=1 整除 p3=2。
在第二个测试用例中,p=[1,2,3] 是一个合法的排列。事实上,所有 6 个长度为 3 的排列都是合法的。
输入解题思路,AI测评打分。不知道怎么写?