Codeforece : 1360C. Similar Pairs(水题)
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(水题)的更多相关文章
- Educational Codeforces Round 10 C. Foe Pairs 水题
C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...
- codeforces 652C Foe Pairs 水题
题意:给你若干个数对,给你一个序列,保证数对中的数都在序列中 对于这个序列,询问有多少个区间,不包含这些数对 分析:然后把这些数对转化成区间,然后对于这些区间排序,然后扫一遍,记录最靠右的左端点就好 ...
- hdu 1051:Wooden Sticks(水题,贪心)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- hdu 2393:Higher Math(计算几何,水题)
Higher Math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 1012:u Calculate e(数学题,水题)
u Calculate e Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 烟大 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 ...
- hdu 1106:排序(水题,字符串处理 + 排序)
排序 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- hdu 1005:Number Sequence(水题)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Codeforces Gym 100531G Grave 水题
Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...
随机推荐
- typora写作
平时写博客,一般采用typora,但是字体颜色和上传到博客园的图片大小和居中问题,总是很糟糕,偶然发现输入法里面还有自定义的短语,能够解决这个问题. <p><img src=&quo ...
- 深入了解UUID:生成、应用与优势
一.引言 在当今数字化时代,唯一标识一个对象的能力变得越来越重要.UUID(Universally Unique Identifier,通用唯一标识符)应运而生,作为一种保证全球唯一性的标识方法,广泛 ...
- 【UniApp】-uni-app-内置组件
前言 好,经过上个章节的介绍完毕之后,了解了一下 uni-app-全局数据和局部数据 那么了解完了uni-app-全局数据和局部数据之后,这篇文章来给大家介绍一下 UniApp 中内置组件 首先不管三 ...
- ConcurrentModificationException日志关键字报警引发的思考
本文将记录和分析日志中的ConcurrentModificationException关键字报警,还有一些我的思考,希望对大家有帮助. 一.背景 近期,在日常的日志关键字报警分析时,发现我负责的一个电 ...
- k8s安装网络插件calico出现error validating "calico.yaml": error validating data: invalid object to validate; if you choose to ignore these errors, turn validation off with --validate=false
解决办法:使用下面版本的calico curl https://docs.projectcalico.org/v3.20/manifests/calico.yaml -O
- LeetCode 503:下一个更大的元素|| (单调栈 or 线段树)
解题思路: 1.单调栈:因为是循环数组,因此把数组复制三遍,ans 数组复制为2倍长,维护一个单调非递增的栈,栈保存的元素是元组(a[i] , i ),如果后面的值有比栈顶元素的值大,栈顶元素出栈,更 ...
- 【UniApp】-uni-app-处理项目输入数据(苹果计算器)
前言 上一篇文章完成了项目的基本布局,这一篇文章我们来处理一下项目的输入数据 项目的输入数据主要是通过按键来输入的,所以我们需要对按键进行处理 那么我们就来看一下 uni-app-处理项目输入数据 步 ...
- beanshell导入java文件
beanshell导入java文件 beanshell可以读取class格式的文件 步骤: a.添加BeanShell预处理程序 b.请求调用 beanshell可以读取java格式的文件 步骤: a ...
- Windows Server 2012 R2在桌面上显示我的电脑等图标
从Windows 2012 开始,微软取消了服务器桌面个性化选项,如何重新调出配置界面,可以使用微软命令.方法如下: 按下「Win鍵」+「R」,在运行里输入: rundll32.exe shell3 ...
- Zabbix自带模板监控MySQL服务
Zabbix的服务端与客户端的安装这里不再赘述了,前面也有相应的文章介绍过了,感兴趣的伙伴们可以看看历史文章就可以了,今天主要介绍下如何利用zabbix自带的模板来监控MySQL服务的一些状态,同时通 ...