CF2188A.Divisible Permutation
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer n. Construct a permutation∗ p of length n satisfying the following condition:
- ∣pi−pi+1∣ is divisible by i for every 1≤i≤n−1.
It can be proven that such a permutation always exists under the constraints of the problem.
∗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,使其满足以下条件:
- 对每个 1≤i≤n−1,∣pi−pi+1∣ 都能被 i 整除。
可以证明,在本题的约束条件下,这样的排列总是存在的。
∗ 长度为 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 the number of test cases t (1≤t≤100). The description of the test cases follows.
The only line of each test case contains a single integer n (2≤n≤100) — the length of the permutation p to be constructed.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤100)。随后是各测试用例的描述。
每个测试用例仅有一行,包含一个整数 n(2≤n≤100)——即待构造的排列 p 的长度。
输出格式
For each test case, output n integers p1,p2,…,pn (1≤pi≤n, all pi-s are distinct) — the permutation you constructed.
If there are multiple valid permutations, you may output any of them.
对于每个测试用例,输出 n 个整数 p1,p2,…,pn(其中 1≤pi≤n,且所有 pi 互不相同)——即你构造出的排列。
若存在多个合法的排列,你可以输出其中任意一个。
输入输出样例
输入#1
2 2 3
输出#1
1 2 2 3 1
说明/提示
In the first test case, p=[1,2] satisfies the condition because ∣p1−p2∣=∣1−2∣=1, which is divisible by 1.
In the second test case, p=[2,3,1] satisfies the condition because:
- ∣p1−p2∣=∣2−3∣=1, which is divisible by 1, and
- ∣p2−p3∣=∣3−1∣=2, which is divisible by 2.
在第一个测试用例中,p=[1,2] 满足条件,因为 ∣p1−p2∣=∣1−2∣=1,而 1 能被 1 整除。
在第二个测试用例中,p=[2,3,1] 满足条件,因为:
- ∣p1−p2∣=∣2−3∣=1,而 1 能被 1 整除;
- ∣p2−p3∣=∣3−1∣=2,而 2 能被 2 整除。
输入解题思路,AI测评打分。不知道怎么写?