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. 【免费】小傅哥 DDD 开发小册

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 大家好,我是技术UP主小傅哥. 如果在面试的时候,面试官问你DDD是什么,你怎么解释?是不是感 ...

  2. ruoyi vue 前后端分离版本 打包分离jar包至lib

    环境:若依前后端分离版本,原打包时将所有的依赖jar包放至ruoyi-admin.jar 包中,该包130MB,过大. 需求:为了减少打包更新上传的时间,减少至1.1mb 1.将不常更新的模块jar包 ...

  3. 用友NCC&WMS&泛微 系统对接案例分享

    用户故事 产品版本:NCC2105 故事是这么开始的,用友全国伙伴社区的社区成员,对我们的多系统集成架构很感兴趣,经常跟我讨论相关系统集成层面的问题:随着企业的发展,由于信息产业的技术含量高,信息系统 ...

  4. jmeter完成文件上传接口

    前提:测试项目中有一个上传本地文件(excel)测被测接口. 测试工具:jmeter 协议:http 测试项目如下图: 第一步:点击模板上传,选择本地excel文件 第二步:上传成功,系统识别exce ...

  5. SpringBoot 异步编程浅谈

    1. 需求背景 当我们需要提高系统的并发性能时,我们可以将耗时的操作异步执行,从而避免线程阻塞,提高系统的并发性能.例如,在处理大量的并发请求时,如果每个请求都是同步阻塞的方式处 理,系统的响应时间会 ...

  6. 组合式api-计算属性computed的使用

    计算属性在vue3中和vue2的思想概念都是一样,唯一区别就是在使用组合式api时候的语法稍有不同. 使用步骤: 导入computed函数 import {computed} from 'vue' 使 ...

  7. 华企盾DSC 恢复密钥需要提供信息

    1.win.ini 2.5097目录复制一份 3.c:\windows\system32\autheninfoset.cfg (64位系统:c:\windows\syswow64\autheninfo ...

  8. 算法1:Fibonacci数列

    斐波那契数列(Fibonacci) 一.背景介绍 斐波那契数列(Fibonacci sequence),又称黄金分割数列,因数学家莱昂纳多·斐波那契(Leonardo Fibonacci)以兔子繁殖为 ...

  9. 【Python】【OpenCV】【NumPy】图像数据的访问

    接上一随笔,这次学习针对图像数据的访问(Numpy.array) 在OpenCV中,使用 imread() 方法可以访问图像,其返回值是一个数组,而根据传入的不同图像,将会返回不同维度的数组. 针对返 ...

  10. Windows下使用C#和32feet.NET开发蓝牙传输功能的记录

    引用的第三方Nuget库 32feet.NET 3.5.0 MaterialDesignColors MaterialDesignThemes Newtonsoft.Json 使用到的技术: XAML ...