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 ...
随机推荐
- MySQL-utf8 和 utf8mb4 区别?
版权声明:原创作品,谢绝转载!否则将追究法律责任. ----- 作者:kirin 1.首先说明一下,版本问题.MySQL8.0之后默认:utf8mb4,而8.0之前默认:latin 2.utf8 和 ...
- Acwing4244牛的比赛
Acwing4244.牛的比赛 题目部分 N 头奶牛,编号 1∼N,一起参加比赛. 奶牛的战斗力两两不同. 这些奶牛之间已经进行了 M轮两两对决. 在对决中,战斗力高的奶牛一定会战胜战斗力低的奶牛. ...
- Vulntarget-b-wp
Vulntarget-b 环境配置 centos7 用户 密码 root root vulntarget root 宝塔Linux面板http://192.168.0.104:8888/045b276 ...
- 别再傻傻地用 ifconfig 查地址了!这条命令足以让你摘掉小白工程师的帽子
大家好,我是民工哥. 众所周知,在 Linux 系统中,ip 和 ifconfig 这个两命令的功能十分相似,ifconfig 是 net-tools 中已被弃用的一个命令,很多年前就已经没有维护了. ...
- Docker下的SqlServer发布订阅启用
一.准备一个Docker的sqlserver #创建挂载数据文件夹 mkdir -p /home/mssql/data #创建挂载日志文件夹 mkdir /home/mssql/log #给文件夹权限 ...
- Map的特性(有序和无序)讨论
目录 什么是红黑树? 在 Java 中,基础java.util.Map 接口本身并不保证元素的顺序.具体的实现类 HashMap 和 TreeMap 的行为(无序.有序)有所不同: HashMap 类 ...
- C#新鲜面试题出炉(2024)
总所周知 C#这门语言 没有Java的八股文,所以面试题一般都是问的业务, 那么对于新手来讲,最起码也要会一些基础性问题, 以下就是包含C# 和sqlserver几个常见的面试题 1) Dele ...
- vue-admin-template动态菜单后台获取菜单
vue-admin-template.vue-element-admin配置动态菜单,菜单数据从后台获取. 我在网上search了几个小时也没有找到想要的emm,翻官网也没有说明,只说明了路由覆盖.只 ...
- LeetCode 947. 移除最多的同行或同列石头 并查集
传送门 思路 干货太干就不太好理解了,以下会有点话痨( ̄▽ ̄)" 首先题目给了一个二维stones数组,存储每个石子的坐标,因为在同行或者同列的石子最终可以被取到只剩下一个,那么我们将同行同 ...
- Flutter GetX的事件监听
Flutter GetX的事件监听 import 'package:flutter/material.dart'; import 'package:flutter_code/page/book/boo ...