https://codeforces.com/contest/1360/problem/C

We call two numbers xx and yy similar if they have the same parity (the same remainder when divided by 22), or if |x−y|=1|x−y|=1. For example, in each of the pairs (2,6)(2,6), (4,3)(4,3), (11,7)(11,7), the numbers are similar to each other, and in the pairs (1,4)(1,4), (3,12)(3,12), they are not.

You are given an array aa of nn (nn 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]a=[11,14,16,12], there is a partition into pairs (11,12)(11,12) and (14,16)(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.

Input

The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases. Then tt test cases follow.

Each test case consists of two lines.

The first line contains an even positive integer nn (2≤n≤502≤n≤50) — length of array aa.

The second line contains nn positive integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100).

Output

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.

Example

input

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

output

YES
NO
YES
YES
YES
YES
NO

Note

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.

思路:当奇数或偶数的个数为偶数的时候输出yes,否则循环查看是否有一组是相邻的数,若有则yes否则no

#include<bits/stdc++.h>
using namespace std;
int i, k, m, n, t, a[60];
int main() {
cin >> t; while (t--) {
cin >> n;
for (i = k = m = 0; i < n; ++i) {
cin >> a[i];
if (a[i] & 1)++m;
}
sort(a, a + n);
for (int i = 1; i < n; ++i) {
if (a[i] - a[i - 1] == 1)++k;
}
if (m & 1 && !k)cout << "NO" << endl;
else cout << "YES" << endl;
}
}

Codeforece : 1360C. Similar Pairs(水题)的更多相关文章

  1. Educational Codeforces Round 10 C. Foe Pairs 水题

    C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...

  2. codeforces 652C Foe Pairs 水题

    题意:给你若干个数对,给你一个序列,保证数对中的数都在序列中 对于这个序列,询问有多少个区间,不包含这些数对 分析:然后把这些数对转化成区间,然后对于这些区间排序,然后扫一遍,记录最靠右的左端点就好 ...

  3. hdu 1051:Wooden Sticks(水题,贪心)

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. poj 1007:DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  5. hdu 2393:Higher Math(计算几何,水题)

    Higher Math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. hdu 1012:u Calculate e(数学题,水题)

    u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  7. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem A: The 3n + 1 problem(水题)

    Problem A: The 3n + 1 problem Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 14  Solved: 6[Submit][St ...

  8. hdu 1106:排序(水题,字符串处理 + 排序)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  9. hdu 1005:Number Sequence(水题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  10. Codeforces Gym 100531G Grave 水题

    Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...

随机推荐

  1. Python根据输入的公司编号、名称、网址,格式化输出公司信息。其中1)冒号统一为英文冒号,编号占6位,不足6位的前面补0。编号后面是制表符。

    根据输入的公司编号.名称.网址,格式化输出公司信息.其中 1)冒号统一为英文冒号,编号占6位,不足6位的前面补0.编号后面是制表符. 2)"公司名称:" 后面输出字符串占8位,左对 ...

  2. python,opencv-python人脸识别,并且发邮件对镜头前未知人员进行报警

    我们在任意一个硬盘的根目录下创建一个Code-project文件夹 在该文件夹下分别创建C-project和Python-project文件夹 在Python-project文件夹下创建face re ...

  3. 期望最大化(EM)算法:从理论到实战全解析

    本文深入探讨了期望最大化(EM)算法的原理.数学基础和应用.通过详尽的定义和具体例子,文章阐释了EM算法在高斯混合模型(GMM)中的应用,并通过Python和PyTorch代码实现进行了实战演示. 关 ...

  4. 平稳扩展:可支持RevenueCat每日12亿次API请求的缓存

    平稳扩展:可支持RevenueCat每日12亿次API请求的缓存 目录 平稳扩展:可支持RevenueCat每日12亿次API请求的缓存 低延迟 建立连接池 故障检测 Up and warm 对故障做 ...

  5. 企业ERP和泛微OA集成场景分析

    轻易云数据集成平台(qeasy.cloud)为企业ERP和泛微OA系统提供了强大的互通解决方案,特别在销售.采购和库存领域的单据审批场景中表现出色.这些场景涉及到多个业务单据的创建和审批,以下是一些具 ...

  6. [CF1168C] And Reachability

    And Reachability 题面翻译 题目描述 Toad Pimple 有一个整数数组 \(a_1,\dots,a_n\). 当 \(x < y\) 且存在 \(x = p_1 < ...

  7. [UOJ#748] [UNR#6 1B] 机器人表演

    在这个科技发达的年代,真人表演已经落伍了.参加完 UOI 后,hehe 蚤去到了下山市大剧院,观看下山市最火爆的机器人表演. 机器人有时比人类更能抓住事情的本质.所谓表演,其实也就是开场有若干个机器人 ...

  8. vue-test4 -----插槽

    <template> <!-- <Main class="cccc"/> <component-a/> --> <slot-d ...

  9. Object.defineProperty用法

    1.能干啥? Object.defineProperty()可以给传入的对象动态的添加或修改属性 2.怎么玩? Object.defineProperty(obj,prop,desc)它有三个参数: ...

  10. Url参数解析组装工具类

    import org.apache.commons.lang3.StringUtils; import java.util.HashMap; import java.util.Map; /** * @ ...