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 ...
随机推荐
- 总结---Django部分(二)
Django中model的SlugField类型字段有什么用途? SlugField字段是将输入的内容中的空格都替换成'-'之后保存,Slug 是一个新闻术语,通常是某些东西的短标签.一个slug只能 ...
- windows server 2019 2012 server 2022 无线网卡驱动安装报错,无线网卡驱动不能安装, inf服务安装段落无效
windows server 2019 无线网络 服务安装段落无效 windows server 2019 无线网卡驱动安装报错,无线网卡驱动不能安装, inf服务安装段落无效 indows serv ...
- java 405_Http状态405-方法不允许
解决方法: 删除下列代码. super.doGet(req.resp); super.doPost(req.resp); 分析: 405错误一般指请求method not allowed 错误. 请求 ...
- jmeter测试计划中的“独立运行每个线程组”Demo演示
一:jmeter的运行顺序 测试计划-->线程组 其次执行顺序为:配置元件.前置处理器.定时器.取样器.后置处理器.断言.监听器 当一个测试计划中有多个线程组,当多个线程组都是是执行状态时,就会 ...
- JOISC2017 题解
\(\text{By DaiRuiChen 007}\) Contest Link A. Cultivation Problem Link 题目大意 在一个 \(r\times c\) 的网格上有 \ ...
- Vite4+Typescript+Vue3+Pinia 从零搭建(7) - request封装
项目代码同步至码云 weiz-vue3-template 基于 axios 封装请求,支持多域名请求地址 安装 npm i axios 封装 utils 目录下新建 request 文件夹,并新建 i ...
- pytest+allure+jenkins+python+git,实现Linux服务器看测试报告,并发送邮件通知
1.简介 pytest:一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高. allure:是开源测试报告框架. jenkins:持 ...
- 【eBPF-02】入门:基于 BCC 框架的程序进阶
本文是 eBPF 系列的第二篇文章,我们来学习 eBPF BCC 框架的进阶用法,对上一篇文章中的代码进行升级,动态输出进程运行时的参数情况. 主要内容包括: 通过 kprobe 挂载内核事件的 eB ...
- Ef Core花里胡哨系列(10) 动态起来的 DbContext
Ef Core花里胡哨系列(10) 动态起来的 DbContext 我们知道,DbContext有两种托管方式,一种是AddDbContext和AddDbContextFactory,但是呢他们各有优 ...
- Python——第二章:元组
元组 tuple 使用小括号组成 特点: 元组是不可变的,固定了某些数据. t = ("张无忌", "赵敏", "呵呵哒") print(t ...