Remove Smallest

简介: Remove Smallest

文章目录

一、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.


本博客给出本题截图:

image.png

image.png

题意:给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;
}

总结

水题,不解释

目录
相关文章
|
9月前
|
Unix Linux 虚拟化
VMware Workstation 17.6.2 发布下载,现在完全免费无论个人还是商业用途
VMware Workstation 17.6.2 发布下载,现在完全免费无论个人还是商业用途
43476 16
VMware Workstation 17.6.2 发布下载,现在完全免费无论个人还是商业用途
|
10月前
|
开发者 UED
ArkTS响应式刷新问题高级用法
本文详细介绍了ArkTS中响应式刷新的高级用法,涵盖Refresh组件的使用、状态管理、条件渲染及精准控制组件刷新。通过实例讲解了Refresh组件的触发条件、事件处理、常用属性,以及如何利用@State、@Link和@Watch装饰器优化状态管理和组件刷新,帮助开发者构建高效、可维护的HarmonyOS应用。
627 0
|
供应链 算法 数据挖掘
【2023年第十一届泰迪杯数据挖掘挑战赛】B题:产品订单的数据分析与需求预测 23页论文及实现代码
本文介绍了2023年第十一届泰迪杯数据挖掘挑战赛B题的解决方案,深入分析了产品订单数据,并使用Arimax和Var模型进行了需求预测,旨在为企业供应链管理提供科学依据,论文共23页并包含实现代码。
349 0
【2023年第十一届泰迪杯数据挖掘挑战赛】B题:产品订单的数据分析与需求预测 23页论文及实现代码
|
机器学习/深度学习 传感器 算法
BO-LSTM回归预测 | Matlab贝叶斯算法优化长短时记忆网络回归预测
BO-LSTM回归预测 | Matlab贝叶斯算法优化长短时记忆网络回归预测
|
11月前
|
自然语言处理 JavaScript Java
Spring 实现 3 种异步流式接口,干掉接口超时烦恼
本文介绍了处理耗时接口的几种异步流式技术,包括 `ResponseBodyEmitter`、`SseEmitter` 和 `StreamingResponseBody`。这些工具可在执行耗时操作时不断向客户端响应处理结果,提升用户体验和系统性能。`ResponseBodyEmitter` 适用于动态生成内容场景,如文件上传进度;`SseEmitter` 用于实时消息推送,如状态更新;`StreamingResponseBody` 则适合大数据量传输,避免内存溢出。文中提供了具体示例和 GitHub 地址,帮助读者更好地理解和应用这些技术。
1815 0
|
存储 安全 Java
ssm666社区流浪动物救助领养系统的设计与开发
ssm666社区流浪动物救助领养系统的设计与开发
|
Linux Shell Android开发
内核,驱动,应用程关系
内核,驱动,应用程关系
227 0
|
缓存 关系型数据库 MySQL
MySQL登录时出现Access denied for user ‘root‘@‘localhost‘ (using password: YES)无法打开的解决方法
MySQL登录时出现Access denied for user ‘root‘@‘localhost‘ (using password: YES)无法打开的解决方法
21309 0
|
Java
图书管理系统(图文详解,附源码)
图书管理系统(图文详解,附源码)
4596 0
|
Ubuntu 网络协议 Linux
Linux: FirewallD和Iptables防火墙 使用
Linux: FirewallD和Iptables防火墙 使用