《技术》学考及选考相关问题请联系张博士13958083702(手机和微信同号) 问题 5305 --Remove Smallest(删除最小数)

5305: Remove Smallest(删除最小数)★★

时间限制: 1 Sec  内存限制: 256 MB
提交: 12  解决: 9
[提交][状态][命题人:]

题目描述

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 a[i] and a[j] is no more than one (|a[i]−a[j]|≤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.

给定数组 a ,由 n 个正(大于零)的整数组成。
可以一次性选择两个指标 i 和 j  (i≠j),使 a[i] 和 a[j] 之间的绝对差不超过1 (|a[i]−a[j]|≤1),并去掉这两个元素中最小的一个。如果两个元素相等,则可以删除其中任何一个元素(但只能删除一个)。
你的任务是确定能否通过若干次(可能是 0 次)这样的操作使数组中只剩一个整数。
你必须回答 t 个独立的测试用例。

输入

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 a[1],a[2],…,a[n] (1≤a[i]≤100), where a[i] is the i-th element of a.

输入的第一行包含一个整数 t(1≤t≤1000)——测试用例的数量。然后是t个测试用例。
每组测试用例的第一行包含一个整数 n (1≤n≤50)- a的长度。测试用例的第二行包含n个整数  a[1],a[2],…,a[n](1≤a[i]≤100),其中 a[i] 是 a 的第 i 个元素。

输出

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.

对于每组测试用例,如果经过若干次操作可以使数组中只剩下一个元素,输出 “YES”(无引号);否则输出“NO”。

样例输入
Copy
5
3
1 2 2
4
5 5 5 5
3
1 2 4
4
1 3 4 4
1
100
样例输出
Copy
YES
YES
NO
NO
YES

提示

In the first test case of the example, we can perform the following sequence of moves:
choose i=1 and j=3 and remove a[i] (so a becomes [2;2]);
choose i=1 and j=2 and remove a[j] (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.
在本例的第一个测试用例中,我们可以执行以下移动序列:
选择 i=1 和 j=3 并删除 a[i] (因此 a 变成[2;2]);
选择 i=1 和 j=2 并删除 a[j] (因此 a 变成[2])。
在这个例子的第二个测试用例中,我们可以选择任何可能的 i 和 j 任意移动,移除哪个元素并不重要。
在本例的第三个测试用例中,没有办法消除2和4。

来源

 

[提交][状态]

如有问题,请咨询客服
浙ICP备20001167号