CF2246A.farmpiggie and Subset Sum
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For a permutation∗ p of even length, you can do the following process:
- Initialize a counter c=0.
- For each i from 1 to n, either add i⋅pi to c, subtract i⋅pi from c, or do nothing.
Let the final value of the counter be cfinal.
Formally, for each i∈1,…,n, consider the set Si=−i⋅pi,0,i⋅pi and choose some xi∈Si. Set cfinal=∑i=1nxi.
You are given a single even integer n. Find any permutation of length n so that regardless of the operations chosen, the final value cfinal will not be 1.
∗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).
对于一个长度为偶数的排列∗ p,你可以执行以下过程:
- 初始化计数器 c=0。
- 对每个 i(从 1 到 n),你可以选择将 i⋅pi 加到 c 上、从 c 中减去 i⋅pi,或者什么也不做。
令计数器的最终值为 cfinal。
形式化地,对每个 i∈{1,…,n},考虑集合 Si={−i⋅pi,0,i⋅pi},并从中任选一个元素 xi∈Si。令 cfinal=∑i=1nxi。
给定一个偶数 n,请构造任意一个长度为 n 的排列,使得无论选择何种操作(即无论每个 xi 如何从对应集合 Si 中选取),最终值 cfinal 都不可能等于 1。
∗一个长度为 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≤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) — the length of the desired permutation.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤25)。随后是各测试用例的描述。
每个测试用例仅有一行,包含一个偶数整数 n(2≤n≤50)——即所求排列的长度。
输出格式
For each test case, output n integers p1,…,pn(1≤pi≤n) — a permutation satisfying the conditions.
If there are multiple solutions, print any of them.
对于每个测试用例,输出 n 个整数 p1,…,pn(1≤pi≤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]. The counter may be incremented in the following 9 ways:
- 0+2⋅12+02
- 0+02+1⋅22
- 0−2⋅1−2+0−2
- 0+02−1⋅2−2
- 0−2⋅1−2+1⋅20
- 0+2⋅12−1⋅20
- 0−2⋅1−2−1⋅2−4
- 0+2⋅12+1⋅24.
- 0+00+00.
None of these are 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] 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=1 at the end.
在第一个测试用例中,输出给出的排列为 [2,1]。计数器可以通过以下 9 种方式递增:
- 0+2⋅12+02
- 0+02+1⋅22
- 0−2⋅1−2+0−2
- 0+02−1⋅2−2
- 0−2⋅1−2+1⋅20
- 0+2⋅12−1⋅20
- 0−2⋅1−2−1⋅2−4
- 0+2⋅12+1⋅24.
- 0+00+00.
以上结果均不等于 1,因此该排列满足给定条件。
我们可以证明第二个测试用例中给出的排列满足该条件。然而,排列 [1,2,3,4] 不满足该条件,因为序列 $$0 \xrightarrow{+1 \cdot 1} 1 \xrightarrow{+0} 1 \xrightarrow{+0} 1 \xrightarrow{+0} 1$$ 最终得到 c=1。
输入解题思路,AI测评打分。不知道怎么写?