A15726 | Matching Numbers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $(a_i, b_i)$ be the pairs that you matched. $\{a_1, b_1, a_2, b_2, \ldots, a_n, b_n\}$ should be a permutation of $\{1, 2, \ldots, 2n\}$ . Let the sorted list of $\{a_1+b_1, a_2+b_2, \ldots, a_n+b_n\}$ be $s_1 < s_2 < \ldots < s_n$ . We must have $s_{i+1}-s_i = 1$ for $1 \le i \le n - 1$ .
Formally, let $(a_i, b_i)$ be the pairs that you matched. $\{a_1, b_1, a_2, b_2, \ldots, a_n, b_n\}$ should be a permutation of $\{1, 2, \ldots, 2n\}$ . Let the sorted list of $\{a_1+b_1, a_2+b_2, \ldots, a_n+b_n\}$ be $s_1 < s_2 < \ldots < s_n$ . We must have $s_{i+1}-s_i = 1$ for $1 \le i \le n - 1$ .
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 500$ ). The description of the test cases follows.
For each test case, a single integer $n$ ( $1 \leq n \leq 10^5$ ) is given.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $10^5$ .
For each test case, a single integer $n$ ( $1 \leq n \leq 10^5$ ) is given.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $10^5$ .
输出格式
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.
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.
输入输出样例
输入 #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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted