CF2246A.farmpiggie and Subset Sum

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

For a permutation∗^{\text{∗}} pp of even length, you can do the following process:

  • Initialize a counter c=0.c = 0.
  • For each ii from 11 to n,n, either add i⋅pii \cdot p_i to cc, subtract i⋅pii \cdot p_i from cc, or do nothing.

Let the final value of the counter be cfinal.c_{\mathrm{final}}.

Formally, for each i∈1,…,n,i \in {1,\ldots,n}, consider the set Si=−i⋅pi,0,i⋅piS_i = {-i \cdot p_i, 0, i \cdot p_i} and choose some xi∈Si.x_i \in S_i. Set cfinal=∑i=1nxi.c_{\mathrm{final}} = \sum_{i = 1}^{n}x_i.

You are given a single even integer nn. Find any permutation of length nn so that regardless of the operations chosen, the final value cfinalc_{\mathrm{final}} will not be 1.1.

∗^{\text{∗}}A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

对于一个长度为偶数的排列∗^{\text{∗}} pp,你可以执行以下过程:

  • 初始化计数器 c=0c = 0。
  • 对每个 ii(从 11 到 nn),你可以选择将 i⋅pii \cdot p_i 加到 cc 上、从 cc 中减去 i⋅pii \cdot p_i,或者什么也不做。

令计数器的最终值为 cfinalc_{\mathrm{final}}。

形式化地,对每个 i∈{1,…,n}i \in \{1,\ldots,n\},考虑集合 Si={−i⋅pi,0,i⋅pi}S_i = \{-i \cdot p_i, 0, i \cdot p_i\},并从中任选一个元素 xi∈Six_i \in S_i。令 cfinal=∑i=1nxic_{\mathrm{final}} = \sum_{i = 1}^{n}x_i。

给定一个偶数 nn,请构造任意一个长度为 nn 的排列,使得无论选择何种操作(即无论每个 xix_i 如何从对应集合 SiS_i 中选取),最终值 cfinalc_{\mathrm{final}} 都不可能等于 11。

∗^{\text{∗}}一个长度为 nn 的排列是指由 11 到 nn 中 nn 个互不相同的整数按任意顺序组成的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,但 [1,2,2][1,2,2] 不是排列(数组中 22 出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中出现了 44)。

输入格式

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

The first and only line of each test case contains a single even integer n (2≤n≤50)n \, (2 \le n \le 50) — the length of the desired permutation.

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

每个测试用例仅有一行,包含一个偶数整数 nn(2≤n≤502 \le n \le 50)——即所求排列的长度。

输出格式

For each test case, output nn integers p1,…,pn (1≤pi≤n)p_1, \ldots, p_n \, (1 \le p_i \le n) — a permutation satisfying the conditions.

If there are multiple solutions, print any of them.

对于每个测试用例,输出 nn 个整数 p1,…,pn (1≤pi≤n)p_1, \ldots, p_n \, (1 \le p_i \le n) —— 一个满足条件的排列。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    2
    4
    6

    输出#1

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

说明/提示

In the first test case, the permutation given in the output is [2,1].[2,1]. The counter may be incremented in the following 99 ways:

  1. 0→+2⋅12→+020 \xrightarrow{+2 \cdot 1} 2 \xrightarrow{+0} 2
  2. 0→+02→+1⋅220 \xrightarrow{+0} 2 \xrightarrow{+1 \cdot 2} 2
  3. 0→−2⋅1−2→+0−20 \xrightarrow{-2 \cdot 1} -2 \xrightarrow{+0} -2
  4. 0→+02→−1⋅2−20 \xrightarrow{+0} 2 \xrightarrow{-1 \cdot 2} -2
  5. 0→−2⋅1−2→+1⋅200 \xrightarrow{-2 \cdot 1} -2 \xrightarrow{+1 \cdot 2} 0
  6. 0→+2⋅12→−1⋅200 \xrightarrow{+2 \cdot 1} 2 \xrightarrow{-1 \cdot 2} 0
  7. 0→−2⋅1−2→−1⋅2−40 \xrightarrow{-2 \cdot 1} -2 \xrightarrow{-1 \cdot 2} -4
  8. 0→+2⋅12→+1⋅24.0 \xrightarrow{+2 \cdot 1} 2 \xrightarrow{+1 \cdot 2} 4.
  9. 0→+00→+00.0 \xrightarrow{+0} 0 \xrightarrow{+0} 0.

None of these are 1,1, so the permutation satisfies the given condition.

We can show that the permutation given in the second test case satisfies the condition. However, the permutation [1,2,3,4][1,2,3,4] would not satisfy the condition, since the sequence $$0 \xrightarrow{+1 \cdot 1} 1 \xrightarrow{+0} 1 \xrightarrow{+0} 1 \xrightarrow{+0} 1$$ results in c=1c = 1 at the end.

在第一个测试用例中,输出给出的排列为 [2,1][2,1]。计数器可以通过以下 99 种方式递增:

  1. 0→+2⋅12→+020 \xrightarrow{+2 \cdot 1} 2 \xrightarrow{+0} 2
  2. 0→+02→+1⋅220 \xrightarrow{+0} 2 \xrightarrow{+1 \cdot 2} 2
  3. 0→−2⋅1−2→+0−20 \xrightarrow{-2 \cdot 1} -2 \xrightarrow{+0} -2
  4. 0→+02→−1⋅2−20 \xrightarrow{+0} 2 \xrightarrow{-1 \cdot 2} -2
  5. 0→−2⋅1−2→+1⋅200 \xrightarrow{-2 \cdot 1} -2 \xrightarrow{+1 \cdot 2} 0
  6. 0→+2⋅12→−1⋅200 \xrightarrow{+2 \cdot 1} 2 \xrightarrow{-1 \cdot 2} 0
  7. 0→−2⋅1−2→−1⋅2−40 \xrightarrow{-2 \cdot 1} -2 \xrightarrow{-1 \cdot 2} -4
  8. 0→+2⋅12→+1⋅24.0 \xrightarrow{+2 \cdot 1} 2 \xrightarrow{+1 \cdot 2} 4.
  9. 0→+00→+00.0 \xrightarrow{+0} 0 \xrightarrow{+0} 0.

以上结果均不等于 11,因此该排列满足给定条件。

我们可以证明第二个测试用例中给出的排列满足该条件。然而,排列 [1,2,3,4][1,2,3,4] 不满足该条件,因为序列 $$0 \xrightarrow{+1 \cdot 1} 1 \xrightarrow{+0} 1 \xrightarrow{+0} 1 \xrightarrow{+0} 1$$ 最终得到 c=1c = 1。

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

首页