A
。
#include "bits/stdc++.h"
using namespace std;
void solve() {
int n;
string s;
cin >> n >> s;
vector<int> cnt(26);
for (int i = 0; i < n; i++) {
cnt[s[i] - 'a']++;
}
sort(cnt.begin(), cnt.end());
for (int i = 0; i < 26; i++) {
if (i > 0 && cnt[i] && cnt[i - 1] && cnt[i] != cnt[i - 1] + 1) {
cout << "NO\n";
return;
}
}
cout << "YES\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
B
。
#include "bits/stdc++.h"
using namespace std;
void solve() {
int x;
cin >> x;
if (x < 4) {
cout << "-1\n";
} else {
cout << (x % 2 ? 1 : 2) << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
C
打表。
。
#include "bits/stdc++.h"
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
iota(a.begin(), a.end(), 1);
if (n == 2) {
cout << "-1\n";
return;
}
if (!(n % 2)) {
swap(a[n - 1] , a[n - 2]);
}
for (int i = 0; i < n; i++) {
cout << a[i] << " \n"[i == n - 1];
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
D
。
#include "bits/stdc++.h"
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
vector<pair<int, int>> pa, pb;
for (int i = 0; i < n; ) {
int j = i;
while (j < n && a[j] == a[i]) {
j++;
}
pa.emplace_back(a[i], j - i);
i = j;
}
for (int i = 0; i < m; ) {
int j = i;
while (j < m && b[j] == b[i]) {
j++;
}
pb.emplace_back(b[i], j - i);
i = j;
}
if (pa.size() != pb.size()) {
cout << "-1\n";
return;
}
int k = pa.size();
int ans = 0;
for (int i = 0; i < k; i++) {
if (pa[i].first != pb[i].first) {
cout << "-1\n";
return;
}
int ca = pa[i].second, cb = pb[i].second;
if (cb < ca) {
cout << "-1\n";
return;
}
int r = 0, c = ca;
while (c < cb) {
c <<= 1;
r++;
}
ans = max(ans, r);
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
E
#include "bits/stdc++.h"
using namespace std;
using i64 = int64_t;
void solve() {
int n;
cin >> n;
vector<i64> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
auto v = a;
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
unordered_map<i64, int> mp;
for (int i = 0; i < n; i++) {
if (!mp.count(a[i])) {
mp[a[i]] = i + 1;
}
}
unordered_map<i64, int> ans;
int m = v.size();
for (int i = 0; i < m; i++) {
int j = i - 1;
while (j >= 0) {
if (v[i] % v[j]) {
ans[v[i]] = mp[v[j]];
break;
}
j--;
}
if (j < 0) {
ans[v[i]] = -1;
}
}
for (int i = 0; i < n; i++) {
cout << ans[a[i]] << " \n"[i == n - 1];
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}