1.A
结论题,最后一个谁赢------>最后一组谁赢------->谁是最终赢家
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1e6+5;
const int mod = 998244353;
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
inline void solve() {
int n; cin >> n;
string s; cin >> s;
cout << s[n - 1] << '\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
std::cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
2.B
找出每个数字出现的次数,若是超过两个不同的数字各自出现次数不小于2就可以
#include<bits/stdc++.h>
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define endl "\n"
using namespace std;
using ll = long long;
using db = double;
const int maxn = 1e6;
const int N = 1e6;
int main()
{
ios::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
int t; cin >> t;
while (t--) {
int n; cin >> n;
vector<int> a(n), b(n, 1);
vector<vector<int>>pos(105);
for (int i = 0; i < n; i++) {
cin >> a[i];
pos[a[i]].push_back(i);
}
bool flag1 = 1, flag2 = 1;
bool success = 0;
for (int i = 1; i <= 100; i++) {
if (pos[i].size() < 2)continue;
if (flag1) { b[pos[i][0]] = 2; flag1 = 0; }
else if (flag2) { b[pos[i][0]] = 3; flag2 = 0; }
if (flag1 == 0 && flag2 == 0) { success = 1; break; }
}
if (success) for (auto i : b)cout << i << " ";
else cout << -1;
cout << endl;
}
return 0;
}
3.C
从最后一位开始,每次迭代就是按照最后一位数字往前挪,挪到谁谁就是下一个最后一位
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5+5;
const int mod = 998244353;
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
inline void solve() {
int n, k; cin >> n >> k;
vector<int>b(n + 1);
bool fg[maxn] = { };
int maxx = 0;
for (int i = 1; i <= n; i++) {
cin >> b[i];
maxx = max(maxx, b[i]);
}
if (maxx <= n || b[n] == n) {
cout << "Yes\n";
return;
}
if (b[n] > n) {
cout << "No\n";
return;
}
int t = b[n];
fg[n] = 1;
int m = n;
while (k--) {
if (t > n) {
cout << "No\n";
return;
}
m = (m - t + n) % n;
t = b[m];
if (fg[m]) {
cout << "Yes\n";
return;
}
else
fg[m] = 1;
}
cout << "Yes\n";
return;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
std::cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
4.D
每一个bi插入小于该bi的最大aj前面
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5+5;
const int mod = 998244353;
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
inline void solve() {
int n, m; cin >> n >> m;
vector<ll>a(n);
vector<ll>b(m);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
sort(b.begin(), b.end(), greater<ll>());
int ans = 0;
for (int i = 0; i < n; i++) {
while (b[ans] >= a[i] && ans < b.size()) {
cout << b[ans++] << ' ';
}
cout << a[i] << ' ';
}
while (ans < b.size())cout << b[ans++] << ' ';
cout << '\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
std::cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}