Codeforces Round

A. Technical Support


Note :One or several.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// #pragma GCC optimize(3)
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void solve() {
int n;
cin >> n;
string s;
cin >> s;
int cnt1 = 0, cnt2 = 0;
for (auto a : s) {
if (a == 'Q') {
cnt1++;
} else {
cnt2 = min(cnt2 + 1, cnt1);
}
}
if (cnt1 <= cnt2)
cout << "Yes" << endl;
else
cout << "No" << endl;
return;
}

signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

B. Kevin and Permutation


巧妙,但感觉做过一道LC的题目类似,找到了!
https://leetcode.cn/problems/beautiful-arrangement-ii/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void solve() {
int n;
cin >> n;

int cnt = n / 2 + 1;
for (int i = 1; i <= n; i++) {
if (i % 2 == 1)
cout << cnt + (i / 2) << ' ';
else
cout << (i / 2) << ' ';
}
cout << endl;
}

signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _ = 1;
cin >> _;
while (_--) {
solve();
}
return 0;
}