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. CTA策略介绍

    CTA策略更多的时候是一种投资方法,更准确的说,主要投资于衍生品的.比较系统化规则化的投资方法都可以称作CTA投资,它并不拘泥于量化或是主动,其具有相当的生命力,会长期存在. CTA策略的收入来源是多 ...

  2. 总结(6)--- python基础知识点小结(细全)

    ==================================================================================================== ...

  3. 【Javaweb】瑞吉外卖你冲不冲?冲冲!冲!冲冲!(数据库环境搭建)(maven项目搭建)一

    图形界面创建数据库(Navicat) 命令行方式创建 瑞吉项目一共涉及到十一张表 导入表结构,既可以使用上面的图形界面,也可以使用MySQL命令: 通过命令导入表结构时,注意sql文件不要放在中文目录 ...

  4. 洛谷2151 [SDOI2009]HH去散步(矩阵快速幂,边点互换)

    题意:HH有个一成不变的习惯,喜欢饭后百步走.所谓百步走,就是散步,就是在一定的时间 内,走过一定的距离. 但是同时HH又是个喜欢变化的人,所以他不会立刻沿着刚刚走来的路走回. 又因为HH是个喜欢变化 ...

  5. linux笔记一(基础命令)

      总结: 1.ls – List ls会列举出当前工作目录的内容(文件或文件夹),就跟你在GUI中打开一个文件夹去看里面的内容一样. 2.mkdir – Make Directory mkdir 用 ...

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

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

  7. Vite4+Typescript+Vue3+Pinia 从零搭建(7) - request封装

    项目代码同步至码云 weiz-vue3-template 基于 axios 封装请求,支持多域名请求地址 安装 npm i axios 封装 utils 目录下新建 request 文件夹,并新建 i ...

  8. 加速计算,为何会成为 AI 时代的计算力“新宠” 审核中

    随着科技的发展,处理大量数据和进行复杂计算的需求越来越高,人工智能.大数据和物联网等领域更是如此,传统的计算方式已经无法满足这些需求.因此,加速计算作为一种现代计算方式,成了必要的手段.加速计算具有前 ...

  9. GaussDB(DWS)中的分布式死锁问题实践

    本文分享自华为云社区<GaussDB(DWS)中的分布式死锁问题实践>,作者: 他强由他强 . 1.什么是分布式死锁 分布式死锁是相对于单机死锁而言,一个事务块中的语句,可能会分散在集群里 ...

  10. Rabbit加密算法

    一.引言 随着信息技术的快速发展,数据安全已成为越来越受到重视的领域.加密算法作为保障数据安全的重要技术手段,在通信.存储等领域得到了广泛应用.Rabbit加密算法作为一种新型的加密算法,凭借其简单易 ...