CF1360C.Similar Pairs
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
我们称两个数 x 和 y 是相似的,如果它们具有相同的奇偶性(即除以 2 的余数相同),或者满足 ∣x−y∣=1。例如,在每一对 (2,6)、(4,3)、(11,7) 中,两个数彼此相似;而在 (1,4)、(3,12) 中则不相似。
给定一个包含 n 个(n 为偶数)正整数的数组 a。请判断是否存在一种将该数组划分为若干对的方式,使得数组中的每个元素恰好属于其中一对,且每对中的两个数都是相似的。
例如,对于数组 a=[11,14,16,12],存在一种划分方式:(11,12) 和 (14,16)。第一对中的数相似是因为它们相差 1;第二对中的数相似是因为它们均为偶数。
输入格式
The first line contains a single integer t (1≤t≤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≤n≤50) — length of array a.
The second line contains n positive integers a1,a2,…,an (1≤ai≤100).
第一行包含一个整数 t(1≤t≤1000)—— 测试用例的数量。随后是 t 个测试用例。
每个测试用例由两行组成。
第一行包含一个偶数正整数 n(2≤n≤50)—— 数组 a 的长度。
第二行包含 n 个正整数 a1,a2,…,an(1≤ai≤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; - 否则输出
NO。
单词 YES 和 NO 中的字母可以使用任意大小写形式。
输入输出样例
输入#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.
第一个测试用例已在题目描述中解释。
在第二个测试用例中,给定的两个数不相似。
在第三个测试用例中,任意一种划分都是可行的。
输入解题思路,AI测评打分。不知道怎么写?