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 ...
随机推荐
- Java笔记——数组静态初始化开始
一维数组: 静态初始化: 定义格式:(1)数据类型[] 数组名 = new 数组类型[] (2)数组类型[] 数组名 ={元素1,元素2,.....} 练习:数组元素逆序: public static ...
- 2023-11-25:用go语言,给定一个数组arr,长度为n,表示n个格子的分数,并且这些格子首尾相连, 孩子不能选相邻的格子,不能回头选,不能选超过一圈, 但是孩子可以决定从任何位置开始选,也可以
2023-11-25:用go语言,给定一个数组arr,长度为n,表示n个格子的分数,并且这些格子首尾相连, 孩子不能选相邻的格子,不能回头选,不能选超过一圈, 但是孩子可以决定从任何位置开始选,也可以 ...
- 【Javaweb】给tomcat添加第三方jar包
就是复制到lib文件夹里面 之后点击jar包右键 选择module library,点击ok就可以了
- Opencv实例练习
实例所用的函数可在另一篇文章查询: https://www.cnblogs.com/Zhouce/p/17867164.html 1.图像读取 1 import cv2 # 引入opencv库 2 ...
- C++ 返回函数指针的函数
目录 0 前言 1 Function Pointer in C/C++ type 1.1 ordinary function Pointer 1.2 non-static member functio ...
- 解密Prompt系列20. LLM Agent之再谈RAG的召回多样性优化
几个月前我们就聊过RAG的经典方案解密Prompt系列14. LLM Agent之搜索应用设计.前几天刚看完openAI在DevDay闭门会议上介绍的RAG相关的经验,有些新的感悟,借此机会再梳理下R ...
- [2020-2021 集训队作业] Tom & Jerry
题目背景 自选题 by ix35 题目描述 给定一张包含 \(n\) 个顶点和 \(m\) 条边的 无向连通图,Tom 和 Jerry 在图上进行了 \(q\) 次追逐游戏. 在第 \(i\) 次游戏 ...
- [USACO2022OPENS] Visits
题目描述 Bessie 的 \(N\)(\(2\le N\le 10^5\))个奶牛伙伴(编号为 \(1\cdots N\))每一个都拥有自己的农场.对于每个 \(1\le i\le N\),伙伴 i ...
- viewPager2页面的切换
使用流程: 1.定义ViewPager 2.为ViewPager创建Adapter ViewPagerAdapter package com.example.viewpagerandfragm ...
- spring cloud生态中Feign、Ribbon、loadbalancer的一些历史
背景 本意是想写个feign中loadbalancer组件和nacos相遇后,一个兼容相关的问题,后面发现Feign这套东西很深,想一篇文章写清楚很难,就先开一篇,讲历史. Feign.OpenFei ...