307468: CF1360C. Similar Pairs

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Similar Pairs

题意翻译

如果两个数$x$和$y$具有相同的奇偶性(除以2时的余数相同),或者$|x-y|=1$,我们称$x$和$y$相似。例如,在数对$(2,6)$,$(4,3)$,$(11,7)$中,数字彼此相似,而在数对$(1,4)$,$(3,12)$中,数字则不相似。 给你一个有$n$($n$是偶数)个正整数的数组$a$,判断是否有一种方法把数组中的数两两配对,使得数组中每个数恰好处于一个数对中并且每个数对中的数彼此相似。 输入格式: 第一行包含一个正整数$t\ (1<=t<=1000)$表示测试样例组数,接下来是$t$组测试样例 每组数据包含两行 第一行包含一个正整数$n\ (2<=n<=50)$表示数组a的长度 第二行包含$n$个正整数$a1,a2...an\ (1<=ai<=100)$ 输出格式: 对于每一组测试样例: 如果这样的分组存在,输出 $YES$ 否则,输出 $NO$

题目描述

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.

输入输出格式

输入格式


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 $ ).

输出格式


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.

输入输出样例

输入样例 #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.

Input

题意翻译

如果两个数$x$和$y$具有相同的奇偶性(除以2时的余数相同),或者$|x-y|=1$,我们称$x$和$y$相似。例如,在数对$(2,6)$,$(4,3)$,$(11,7)$中,数字彼此相似,而在数对$(1,4)$,$(3,12)$中,数字则不相似。 给你一个有$n$($n$是偶数)个正整数的数组$a$,判断是否有一种方法把数组中的数两两配对,使得数组中每个数恰好处于一个数对中并且每个数对中的数彼此相似。 输入格式: 第一行包含一个正整数$t\ (1<=t<=1000)$表示测试样例组数,接下来是$t$组测试样例 每组数据包含两行 第一行包含一个正整数$n\ (2<=n<=50)$表示数组a的长度 第二行包含$n$个正整数$a1,a2...an\ (1<=ai<=100)$ 输出格式: 对于每一组测试样例: 如果这样的分组存在,输出 $YES$ 否则,输出 $NO$

加入题单

算法标签: