文章目录

  • 一、Remove Smallest
  • 总结

一、Remove Smallest

本题链接:Remove Smallest

题目
A. Remove Smallest
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.

本博客给出本题截图

题意:给t组数字串,对于每组数字有两种操作:挑选两个绝对值相差1的数,并删除其中的小数;挑选两个值相同的数字并任意删除一个数

AC代码

#include <iostream>
#include <algorithm>using namespace std;const int N = 60;int a[N];int main()
{int t;cin >> t;while (t -- ){int n;cin >> n;for (int i = 0; i < n; i ++ ) cin >> a[i];if (n == 1){puts("YES");continue;}sort(a, a + n);int cnt = 0;for (int i = 0; i < n - 1; i ++ ) if (a[i + 1] - a[i] == 1 || a[i + 1] == a[i])cnt ++;if (cnt == n - 1) puts("YES");else puts("NO");}return 0;
}

总结

水题,不解释

Remove Smallest相关推荐

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

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

  2. Codeforces Round #661 (Div. 3)

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

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

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

  4. Python基本手册

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

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

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

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

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

  7. Python基础——学习手册

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

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

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

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

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

最新文章

  1. git修改远程仓库地址
  2. 使用Web.Config Transformation配置灵活的配置文件
  3. 租车java 查询_基于java实现租车管理系统
  4. PAT甲级1004 Counting Leaves (30分):[C++题解]树、邻接表存储树、dfs遍历树
  5. Java 面试经典题解析:谈谈你对 Java 平台的理解?
  6. java_OA管理系统(一):Servlet总结案例仿网络聊天室
  7. Callable、Future、FutureTask浅析
  8. iOS html5使用缓存并及时更新方案总结
  9. 会不会导致内存泄漏_Java内存泄漏!为什么会泄漏?如何泄漏?怎么定位?
  10. 极简好看的个人介绍页源码
  11. 剑指offer 56 - 1.数组中数字出现的次数
  12. Java NIO学习篇之通道FileChannel详解
  13. 糖尿病监测中国际通用的“金标准”
  14. IMX6ULL uboot启动分析(五)
  15. 基于阿里开源的COLA架构和DDD领域驱动设计构建货物运输系统
  16. 机智云发布机智云5.0 实现物联网应用协同开发
  17. 微信开放平台开源_开源需要开放徽章的3个原因
  18. keil的sct文件_(转)KEIL下分散加载文件 **.sct文件
  19. 嵌入式Linux--Lichee Pi Zero原理图分析
  20. 【历史上的今天】7 月 28 日:Lua 首次在线上运行;苹果停产所有非 iOS 的 iPod;戴尔工作站 400 推出

热门文章

  1. 如何在Mac上的Photo Booth中应用效果?
  2. 免费注册微软Windows Live企业邮箱的方法详解
  3. DSP与CPU的区别
  4. 小米笔记本售后键盘失灵失望记录!
  5. creator项目上线4399小游戏
  6. UG 10.0 NX 安装视频教程
  7. python开发购物网站_python实现简单购物商城
  8. 基于java+springboot+mybatis+vue+mysql的化妆品销售商城网站
  9. 斗地主Java课程设计_JAVA面向对象编程课程设计——web版斗地主
  10. CCNA考试要点大搜集(一)