#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> possibleHayTypes(vector<int>& hayTypes, int N) {
int maxCount = 0;
int currentType = -1;
int currentCount = 0;
for (int i = 0; i < N; ++i) {
if (hayTypes[i] == currentType) {
++currentCount;
} else {
if (currentCount > N / 2) {
maxCount = max(maxCount, currentCount);
}
currentType = hayTypes[i];
currentCount = 1;
}
}
if (currentCount > N / 2) {
maxCount = max(maxCount, currentCount);
}
vector<int> possibleTypes;
if (maxCount > N / 2) {
for (int i = 1; i <= N; ++i) {
if (count(hayTypes.begin(), hayTypes.end(), i) > N / 2) {
possibleTypes.push_back(i);
}
}
sort(possibleTypes.begin(), possibleTypes.end());
} else {
possibleTypes.push_back(-1);
}
return possibleTypes;
}
int main() {
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
vector<int> hayTypes(N);
for (int i = 0; i < N; ++i) {
cin >> hayTypes[i];
}
vector<int> result = possibleHayTypes(hayTypes, N);
if (result.size() == 1 && result[0] == -1) {
cout << -1 << endl;
} else {
for (size_t i = 0; i < result.size(); ++i) {
cout << result[i];
if (i < result.size() - 1) cout << " ";
}
cout << endl;
}
}
return 0;
}
~~~WATER PLUS~~~
最新推荐文章于 2024-09-16 12:36:03 发布