CF2233B.Different Distances

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Construct an array of 4⋅n4 \cdot n integers such that:

  • each number 1,2,…,n1, 2, \dots, n appears in the array exactly 44 times;
  • let px,ip_{x, i} be the position of the ii-th occurrence of number xx in the array; then, for each xx from 11 to nn, the numbers (px,2−px,1),(px,3−px,2),(px,4−px,3)(p_{x, 2} - p_{x, 1}), (p_{x, 3} - p_{x, 2}), (p_{x, 4} - p_{x, 3}) must be pairwise distinct.

For example, for n=3n = 3, one possible array is [1,1,2,1,2,3,1,3,2,2,3,3][1, 1, 2, 1, 2, 3, 1, 3, 2, 2, 3, 3], because:

  • p1,2−p1,1=1,p1,3−p1,2=2,p1,4−p1,3=3p_{1, 2} - p_{1, 1} = 1, p_{1, 3} - p_{1, 2} = 2, p_{1, 4} - p_{1, 3} = 3 — all numbers are distinct;
  • p2,2−p2,1=2,p2,3−p2,2=4,p2,4−p2,3=1p_{2, 2} - p_{2, 1} = 2, p_{2, 3} - p_{2, 2} = 4, p_{2, 4} - p_{2, 3} = 1 — all numbers are distinct;
  • p3,2−p3,1=2,p3,3−p3,2=3,p3,4−p3,3=1p_{3, 2} - p_{3, 1} = 2, p_{3, 3} - p_{3, 2} = 3, p_{3, 4} - p_{3, 3} = 1 — all numbers are distinct.

构造一个包含 4⋅n4 \cdot n 个整数的数组,使得:

  • 每个数字 1,2,…,n1, 2, \dots, n 在数组中恰好出现 44 次;
  • 设 px,ip_{x, i} 表示数字 xx 在数组中第 ii 次出现的位置;则对每个从 11 到 nn 的 xx,三个差值 (px,2−px,1)(p_{x, 2} - p_{x, 1})、(px,3−px,2)(p_{x, 3} - p_{x, 2})、(px,4−px,3)(p_{x, 4} - p_{x, 3}) 必须两两不同。

例如,当 n=3n = 3 时,一个可能的数组是 [1,1,2,1,2,3,1,3,2,2,3,3][1, 1, 2, 1, 2, 3, 1, 3, 2, 2, 3, 3],因为:

  • p1,2−p1,1=1p_{1, 2} - p_{1, 1} = 1,p1,3−p1,2=2p_{1, 3} - p_{1, 2} = 2,p1,4−p1,3=3p_{1, 4} - p_{1, 3} = 3 —— 这三个数互不相同;
  • p2,2−p2,1=2p_{2, 2} - p_{2, 1} = 2,p2,3−p2,2=4p_{2, 3} - p_{2, 2} = 4,p2,4−p2,3=1p_{2, 4} - p_{2, 3} = 1 —— 这三个数互不相同;
  • p3,2−p3,1=2p_{3, 2} - p_{3, 1} = 2,p3,3−p3,2=3p_{3, 3} - p_{3, 2} = 3,p3,4−p3,3=1p_{3, 4} - p_{3, 3} = 1 —— 这三个数互不相同。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤2001 \le t \le 200). The description of the test cases follows.

The only line of each test case contains one integer nn (2≤n≤2002 \le n \le 200).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤2001 \le t \le 200)。随后是测试用例的描述。

每个测试用例仅有一行,包含一个整数 nn(2≤n≤2002 \le n \le 200)。

输出格式

For each test case, output the required array. If there are several suitable arrays, output any of them. It can be shown that at least one suitable array always exists under the constraints of the problem.

对于每个测试用例,输出所要求的数组。如果存在多个符合条件的数组,则输出其中任意一个即可。在本题的约束条件下,可以证明至少存在一个符合条件的数组。

输入输出样例

  • 输入#1

    3
    3
    4
    5

    输出#1

    1 1 2 1 2 3 1 3 2 2 3 3
    1 4 3 4 4 3 3 1 2 1 2 3 4 2 2 1 
    5 3 2 4 1 2 2 4 4 5 3 5 2 1 3 1 5 4 1 3

说明/提示

null

输入解题思路,AI测评打分。不知道怎么写?

首页