CF1399A Remove Smallest

23 篇文章 0 订阅

原题链接: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.

题目大意

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

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

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

题解

时隔一年半再 O I OI OI,爷青回。

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

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

代码

退役老咸鱼含泪复习了 s c a n f   p r i n t f   m e m s e t scanf\ printf\ memset scanf printf memset以及 s o r t sort sort的用法。

#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();}
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShadyPi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值