Increasing
You are given an array aa of nn positive integers. Determine if, by rearranging the elements, you can make the array strictly increasing. In other words, determine if it is possible to rearrange the elements such that a_1 < a_2 < \dots < a_na1<a2<⋯<an holds.
Input
The first line contains a single integer tt (1 \leq t \leq 1001≤t≤100) — the number of test cases.
The first line of each test case contains a single integer nn (1 \leq n \leq 1001≤n≤100) — the length of the array.
The second line of each test case contains nn integers a_iai (1 \leq a_i \leq 10^91≤ai≤109) — the elements of the array.
Output
For each test case, output "YES" (without quotes) if the array satisfies the condition, and "NO" (without quotes) otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
Sample 1
Inputcopy | Outputcopy |
---|---|
3 4 1 1 1 1 5 8 7 1 3 4 1 5 | NO YES YES |
Note
In the first test case any rearrangement will keep the array [1,1,1,1][1,1,1,1], which is not strictly increasing.
In the second test case, you can make the array [1,3,4,7,8][1,3,4,7,8].
——判断有没有相等元素即可,不能开数组存,耗时耗空间
#include <iostream>
#include <cstring>
#include <set>
using namespace std;
int main()
{
int t;
cin >> t;
set<long long> s;
for(int i=1;i<=t;i++)
{
s.clear();
long long n, x, f = 0;
cin >> n;
for(int j=1;j<=n;j++)
{
int ls = s.size();
cin >> x;
s.insert(x);
//注意,尽管已经判断无法获得绝对增加数组,
//也要让他继续跑,因为还有元素未输入
if (ls == s.size()&&f==0)
{
f = 1;
cout << "NO" << endl;
}
}
if (f == 0)
{
cout << "YES" << endl;
}
//cout << "&" << endl;
/*for (set<long long>::iterator it = s.begin(); it != s.end(); it++)
{
cout << *it << " ";
}
cout << endl;*/
}
}