CF1788C.Matching Numbers
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer n. Pair the integers 1 to 2n (i.e. each integer should be in exactly one pair) so that each sum of matched pairs is consecutive and distinct.
Formally, let (ai,bi) be the pairs that you matched. a1,b1,a2,b2,…,an,bn should be a permutation of 1,2,…,2n. Let the sorted list of a1+b1,a2+b2,…,an+bn be s1<s2<…<sn. We must have si+1−si=1 for 1≤i≤n−1.
给你一个整数 n。将整数 1 到 2n 两两配对(即每个整数恰好出现在一个配对中),使得每对配对的和构成一个连续且互不相同的序列。
形式化地,设 (ai,bi) 为你所构造的配对,则集合 {a1,b1,a2,b2,…,an,bn} 应为 {1,2,…,2n} 的一个排列。令 {a1+b1,a2+b2,…,an+bn} 的升序排列为 s1<s2<…<sn。要求对所有 1≤i≤n−1,满足 si+1−si=1。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤500). The description of the test cases follows.
For each test case, a single integer n (1≤n≤105) is given.
It is guaranteed that the sum of n over all test cases doesn't exceed 105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤500)。随后是各测试用例的描述。
对于每个测试用例,给定一个整数 n(1≤n≤105)。
保证所有测试用例的 n 之和不超过 105。
输出格式
For each test case, if it is impossible to make such a pairing, print "No".
Otherwise, print "Yes" followed by n lines.
At each line, print two integers that are paired.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
If there are multiple solutions, print any.
对于每个测试用例,若无法完成这样的配对,则输出“No”。
否则,先输出“Yes”,然后输出 n 行。
每行输出两个被配对的整数。
答案的大小写不限(即可以是大写或小写)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均会被识别为肯定回答。
若存在多个解,输出任意一个即可。
输入输出样例
输入#1
4 1 2 3 4
输出#1
Yes 1 2 No Yes 1 6 3 5 4 2 No
说明/提示
For the third test case, each integer from 1 to 6 appears once. The sums of matched pairs are 4+2=6, 1+6=7, and 3+5=8, which are consecutive and distinct.
对于第三个测试用例,从 1 到 6 的每个整数均恰好出现一次。配对后的和分别为 4+2=6、1+6=7 和 3+5=8,这些和互不相同且构成连续整数。
输入解题思路,AI测评打分。不知道怎么写?