原题链接:http://codeforces.com/problemset/problem/1399/A

Remove Smallest

You are given the array a consisting of n positive (greater than zero) integers.

In one move, you can choose two indices i and j (i≠j) such that the absolute difference between ai and aj is no more than one (|ai−aj|≤1) and remove the smallest of these two elements. If two elements are equal, you can remove any of them (but exactly one).

Your task is to find if it is possible to obtain the array consisting of only one element using several (possibly, zero) such moves or not.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1≤t≤1000) — the number of test cases. Then t test cases follow.

The first line of the test case contains one integer n (1≤n≤50) — the length of a. The second line of the test case contains n integers a1,a2,…,an (1≤ai≤100), where ai is the i-th element of a.

Output

For each test case, print the answer: “YES” if it is possible to obtain the array consisting of only one element using several (possibly, zero) moves described in the problem statement, or “NO” otherwise.

Example
input

5
3
1 2 2
4
5 5 5 5
3
1 2 4
4
1 3 4 4
1
100

output

YES
YES
NO
NO
YES

Note

In the first test case of the example, we can perform the following sequence of moves:

choose i=1 and j=3 and remove ai (so a becomes [2;2]);
choose i=1 and j=2 and remove aj (so a becomes [2]).
In the second test case of the example, we can choose any possible i and j any move and it doesn’t matter which element we remove.

In the third test case of the example, there is no way to get rid of 2 and 4.

题目大意

ttt组询问,每组给一个nnn以及由nnn个数字组成的数列。

每次操作可以选择任意两个绝对值只差≤1\le 1≤1的数字,去掉其中较小的一个,若两数字相同则去掉任意一个。

问这个数列最后能否被消除到只剩一个数。

题解

时隔一年半再OIOIOI,爷青回。

想要消掉最小的那个数aaa,必须要找一个bbb满足a≤b≤a+1a\le b\le a+1a≤b≤a+1,在消掉aaa以后,bbb就变成了最小的数,于是以此类推,只要对于当前最小值aaa找不到符合要求的bbb,这个数列就不可能被消到只剩一个。

要实现的话,排个序就好了。

代码

退役老咸鱼含泪复习了scanfprintfmemsetscanf\ printf\ memsetscanf printf memset以及sortsortsort的用法。

#include<bits/stdc++.h>
using namespace std;
int t,a;
int num[55];
void in()
{scanf("%d",&a);memset(num,105,sizeof(num));for(int i=1;i<=a;++i)scanf("%d",&num[i]);
}
void ac()
{sort(num+1,num+1+a);for(int i=1;i<a;++i)if(num[i+1]-num[i]>1){printf("NO\n");return;}printf("YES\n");
}
int main()
{scanf("%d",&t);for(int i=1;i<=t;++i){in(),ac();}
}

CF1399A Remove Smallest相关推荐

  1. Remove Smallest

    文章目录 一.Remove Smallest 总结 一.Remove Smallest 本题链接:Remove Smallest 题目: A. Remove Smallest time limit p ...

  2. Codeforces Round #661 (Div. 3)题解

    目录 A.Remove Smallest(模拟) B.Gifts Fixing(模拟) C.Boats Competition(暴力枚举) D.Binary String To Subsequence ...

  3. Codeforces Round #661 (Div. 3)

    A - Remove Smallest 排个序,如果相邻的数大于一就不满足题意 #define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) ...

  4. 【数据结构与算法】二叉堆V2.0的Java实现

    更新说明 我们在此前已经编写过简单版的二叉大根堆V1.0,这次,换成二叉小根堆,命名为二叉堆V2.0. 大家也知道,堆是完全二叉树,存储方式借助动态数组实现顺序存储,依赖于父子结点之间的index关系 ...

  5. Python基本手册

    Python基本手册 关键词: Python Python基本手册 常见内置函数 标准库 爬虫 1 GET 2 POST 3 Headers 字符串 模块 1 定义模块 2 常用的字符串方法 列表li ...

  6. 《算法图解》学习笔记(二):选择排序(附代码)

    欢迎关注WX公众号:[程序员管小亮] python学习之路 - 从入门到精通到大师 文章目录 欢迎关注WX公众号:[程序员管小亮] [python学习之路 - 从入门到精通到大师](https://b ...

  7. python 怎么让列表里的数从大到小排列_Python实现把列表里的数字按从小到大的顺序排列...

    一.自己造轮子 第一种方式的思路: 拿出列表里的第0个元素,把它赋给一个叫做"最小值"的变量,然后用这个变量去跟后面的每个数字一一对比,如果碰到比它小的,就把那个新发现的小数字赋给 ...

  8. Python基础——学习手册

    Python基本手册 常见内置函数 标准库 爬虫 1 GET 2 POST 3 Headers 字符串 模块 1 定义模块 2 常用的字符串方法 列表list 1 列表相关的内置函数 2 列表元素的循 ...

  9. 代码不规范,同事两行泪?

    最近参加了一个比赛,然后看到队友编程的代码,我觉得真的是觉得注释和命名规范的重要性了,因为几乎每个字符都要咨询他,用老师的话来说,这就是命名不规范的后续反应.所以此时的我意识到写一篇关于注释程序的重要 ...

  10. LeetCode 316. Remove Duplicate Letters--贪心--Java,C++,Python解法

    题目地址:Number of Longest Increasing Subsequence - LeetCode 做这道题目前建议先做:Longest Increasing Subsequence - ...

最新文章

  1. 《公安机关互联网安全监督检查规定》今日起实施,要检查你家的数据中心了...
  2. c语言考试算法,c语言考试常用算法docx.docx
  3. HDU 5510 Bazinga
  4. Luogu P1041 [2003NOIP提高组]传染病控制
  5. 去除 Css 表单自动填充黄色背景
  6. 苏浪浪 201771010120 第三周 Java基本程序设计总结
  7. tensorflow之get_shape
  8. oracle11g服务配置,oracle11g dg broker配置服务的高可用
  9. Linux基础知识总结一
  10. NDP调查:P2P下载的视频中60%为情色内容
  11. 微信小程序毕业设计 基于微信共享小程序系统开题报告
  12. 关于Mac学习C语言通过vscode如何编译运行代码
  13. 《基于MFC的OpenGL编程》Part 7 Animation
  14. 360“隐私保护器”真相
  15. nn.functional.normalize
  16. 微信小程序开发者工具的使用
  17. Spring Boot缓存实战 Redis 设置有效时间和自动刷新缓存
  18. 相关分析怎么进行?有哪些条件?
  19. 50个超酷的Photoshop的渐变画笔
  20. 欧拉函数-matlab代码

热门文章

  1. html缓存失败是什么,HTML5离线“应用程序缓存错误事件:清单读取失败(-1)”...
  2. 360 php SQL注入,php中sql注入漏洞示例
  3. java 文件工具类_java文件工具类,文件的一些基本操作
  4. let var const的区别
  5. Oracle rac11g 安装报INS41112
  6. vue-methods三种调用的形势
  7. LPDIRECTDRAW7编译错误的解决方法
  8. C# ToString
  9. 关于Entity Data model掌握灵活的数据模型 EntityFramework(1)(翻译)
  10. 开机后网络连接迟迟没有反映是怎么回事?