A13543 | Similar Pairs
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
We call two numbers $x$ and $y$ similar if they have the same parity (the same remainder when divided by $2$ ), or if $|x-y|=1$ . For example, in each of the pairs $(2, 6)$ , $(4, 3)$ , $(11, 7)$ , the numbers are similar to each other, and in the pairs $(1, 4)$ , $(3, 12)$ , they are not.
You are given an array $a$ of $n$ ( $n$ is even) positive integers. Check if there is such a partition of the array into pairs that each element of the array belongs to exactly one pair and the numbers in each pair are similar to each other.
For example, for the array $a = [11, 14, 16, 12]$ , there is a partition into pairs $(11, 12)$ and $(14, 16)$ . The numbers in the first pair are similar because they differ by one, and in the second pair because they are both even.
You are given an array $a$ of $n$ ( $n$ is even) positive integers. Check if there is such a partition of the array into pairs that each element of the array belongs to exactly one pair and the numbers in each pair are similar to each other.
For example, for the array $a = [11, 14, 16, 12]$ , there is a partition into pairs $(11, 12)$ and $(14, 16)$ . The numbers in the first pair are similar because they differ by one, and in the second pair because they are both even.
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases. Then $t$ test cases follow.
Each test case consists of two lines.
The first line contains an even positive integer $n$ ( $2 \le n \le 50$ ) — length of array $a$ .
The second line contains $n$ positive integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 100$ ).
Each test case consists of two lines.
The first line contains an even positive integer $n$ ( $2 \le n \le 50$ ) — length of array $a$ .
The second line contains $n$ positive integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 100$ ).
输出格式
For each test case print:
- YES if the such a partition exists,
- NO otherwise.
The letters in the words YES and NO can be displayed in any case.
- YES if the such a partition exists,
- NO otherwise.
The letters in the words YES and NO can be displayed in any case.
输入输出样例
输入 #1
7 4 11 14 16 12 2 1 8 4 1 1 1 1 4 1 2 5 6 2 12 13 6 1 6 3 10 5 8 6 1 12 3 10 5 8
输出 #1
YES NO YES YES YES YES NO
The first test case was explained in the statement.
In the second test case, the two given numbers are not similar.
In the third test case, any partition is suitable.
In the second test case, the two given numbers are not similar.
In the third test case, any partition is suitable.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted