CF1399A.Remove Smallest
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
给你一个由 n 个正整数(均大于零)组成的数组 a。
在一次操作中,你可以选择两个下标 i 和 j(i=j),满足 ai 与 aj 的绝对差值不超过 1(即 ∣ai−aj∣≤1),然后移除这两个元素中较小的那个。若两元素相等,则可任选其一移除(但必须恰好移除一个)。
你的任务是判断:能否通过若干次(可能为零次)这样的操作,最终使数组仅剩一个元素。
你需要回答 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 a1,a2,…,an (1≤ai≤100), where ai is the i-th element of a.
输入的第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含一个整数 n(1≤n≤50),表示数组 a 的长度。每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤100),其中 ai 是数组 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"。
输入输出样例
输入#1
5 3 1 2 2 4 5 5 5 5 3 1 2 4 4 1 3 4 4 1 100
输出#1
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 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.
在示例的第一个测试用例中,我们可以执行以下操作序列:
- 选择 i=1 和 j=3,并移除 ai(此时 a 变为 [2;2]);
- 选择 i=1 和 j=2,并移除 aj(此时 a 变为 [2])。
在示例的第二个测试用例中,每次操作均可任选 i 和 j,且移除哪个元素均无影响。
在示例的第三个测试用例中,无法同时消除 2 和 4。
输入解题思路,AI测评打分。不知道怎么写?