CF1526A.Mean Inequality

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa of 2n2n distinct integers. You want to arrange the elements of the array in a circle such that no element is equal to the the arithmetic mean of its 22 neighbours.

More formally, find an array bb, such that:

  • bb is a permutation of aa.

  • For every ii from 11 to 2n2n, bi≠bi−1+bi+12b_i \neq \frac{b_{i-1}+b_{i+1}}{2}, where b0=b2nb_0 = b_{2n} and b2n+1=b1b_{2n+1} = b_1.

It can be proved that under the constraints of this problem, such array bb always exists.

给你一个包含 2n2n 个互不相同整数的数组 aa。你需要将该数组的元素排成一个环形,使得任意一个元素都不等于其两个相邻元素的算术平均值。

更准确地说,请找出一个数组 bb,满足:

  • bb 是 aa 的一个排列;

  • 对每个从 11 到 2n2n 的 ii,均有 bi≠bi−1+bi+12b_i \neq \frac{b_{i-1}+b_{i+1}}{2},其中规定 b0=b2nb_0 = b_{2n} 且 b2n+1=b1b_{2n+1} = b_1。

可以证明,在本题的约束条件下,这样的数组 bb 总是存在的。

输入格式

The first line of input contains a single integer tt (1≤t≤1000)(1 \leq t \leq 1000) — the number of testcases. The description of testcases follows.

The first line of each testcase contains a single integer nn (1≤n≤25)(1 \leq n \leq 25).

The second line of each testcase contains 2n2n integers a1,a2,…,a2na_1, a_2, \ldots, a_{2n} (1≤ai≤109)(1 \leq a_i \leq 10^9) — elements of the array.

Note that there is no limit to the sum of nn over all testcases.

输入的第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000)—— 表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤251 \leq n \leq 25)。

每个测试用例的第二行包含 2n2n 个整数 a1,a2,…,a2na_1, a_2, \ldots, a_{2n}(1≤ai≤1091 \leq a_i \leq 10^9)—— 表示数组的元素。

注意:所有测试用例的 nn 值之和没有限制。

输出格式

For each testcase, you should output 2n2n integers, b1,b2,…b2nb_1, b_2, \ldots b_{2n}, for which the conditions from the statement are satisfied.

对于每个测试用例,你应该输出 2n2n 个整数 b1,b2,…,b2nb_1, b_2, \ldots, b_{2n},使得题目陈述中的条件得到满足。

输入输出样例

  • 输入#1

    3
    3
    1 2 3 4 5 6
    2
    123 456 789 10
    1
    6 9

    输出#1

    3 1 4 2 5 6
    123 10 456 789
    9 6

说明/提示

In the first testcase, array [3,1,4,2,5,6][3, 1, 4, 2, 5, 6] works, as it's a permutation of [1,2,3,4,5,6][1, 2, 3, 4, 5, 6], and 3+42≠1\frac{3+4}{2}\neq 1, 1+22≠4\frac{1+2}{2}\neq 4, 4+52≠2\frac{4+5}{2}\neq 2, 2+62≠5\frac{2+6}{2}\neq 5, 5+32≠6\frac{5+3}{2}\neq 6, 6+12≠3\frac{6+1}{2}\neq 3.

在第一个测试用例中,数组 [3,1,4,2,5,6][3, 1, 4, 2, 5, 6] 满足要求,因为它是一个 [1,2,3,4,5,6][1, 2, 3, 4, 5, 6] 的排列,且满足 3+42≠1\frac{3+4}{2}\neq 1,1+22≠4\frac{1+2}{2}\neq 4,4+52≠2\frac{4+5}{2}\neq 2,2+62≠5\frac{2+6}{2}\neq 5,5+32≠6\frac{5+3}{2}\neq 6,6+12≠3\frac{6+1}{2}\neq 3。

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

首页