总览

Complete

Solutions

A. Trippi Troppi

Solve

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
string ans;
string tmp;
while (t--) {
for (int i = 1; i <= 3; ++i) {
cin >> tmp;
ans += tmp[0];
}
cout << ans << '\n';
ans = "";
}
return 0;
}

B. Bobritto Bandito

Solve

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin >> t;
while (t--) {
int n, m, l, r;
cin >> n >> m >> l >> r;
int sub_l = l, sub_r = r;
while (sub_r - sub_l > m) {
if (abs(sub_r) > abs (sub_l)) {
sub_r--;
} else {
sub_l++;
}
}
cout << sub_l << ' ' << sub_r << '\n';
}
return 0;
}

C. Brr Brrr Patapim

Solve

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
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()

int main() {
int t;
cin >> t;
vector<int> ans;
while (t--) {
int n;
cin >> n;
ans.resize(2 * n, 0);
unordered_set<int> s;

for (int i = 0, temp; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> temp;
if ((i + j + 1) < 2 * n) {
s.insert(temp);
ans[i + j + 1] = temp;
}
}
}
for (int i = 1; i <= 2 * n; ++i) {
if (s.find(i) == s.end()) {
ans[0] = i;
}
}
for_each(all(ans), [](int n) {
cout << n << ' ';
});
cout << '\n';
}
return 0;
}

D. Tung Tung Sahur

Solve

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
36
37
38
39
40
41
42
#include <bits/stdc++.h>
using namespace std;
void solve(int t) {
while (t--) {
string p, cmp;
cin >> p >> cmp;
int i = 0, j = 0;
bool flag = true;
// 使用 && 只在两个字符串都有字符时进入循环
while (i < p.length() && j < cmp.length()) {
int li = i, lj = j;

while (i < p.length() && p[i] == p[li]) ++i;
while (j < cmp.length() && cmp[j] == cmp[lj]) ++j;

// 检查当前两组字符是否一致(字符必须相同)
if (p[li] != cmp[lj]) {
flag = false;
break;
}
int cnt_p = i - li, cnt_cmp = j - lj;
// 检查 cmp 的数量是否在合法范围内
if (cnt_cmp < cnt_p || cnt_cmp > 2 * cnt_p) {
flag = false;
break;
}
}
// 遍历结束后,如果两字符串未同时结束则说明不匹配
if (i != p.length() || j != cmp.length()) {
flag = false;
}
cout << (flag ? "YES" : "NO") << '\n';
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int t;
cin >> t;
solve(t);
return 0;
}

E. Boneca Ambalabu

Solve

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int MAX_BITS = 31;
int t, n;

// 正解
void solve() {
cin >> n;
vector<int> a(n);
for (auto &x : a) cin >> x;

// 统计每一位上有多少个 1
vector<int> bitCount(MAX_BITS, 0);
for (int i = 0; i < n; ++i) {
for (int b = 0; b < MAX_BITS; ++b) {
if ((a[i] >> b) & 1) {
bitCount[b]++;
}
}
}

int ans = 0;
for (int i = 0; i < n; ++i) {
int total = 0;
for (int b = 0; b < MAX_BITS; ++b) {
int cnt1 = bitCount[b];
int cnt0 = n - cnt1;
if ((a[i] >> b) & 1) {
// 当前数该位为 1,与 cnt0 个 0 异或为 1
total += cnt0 * (1LL << b);
} else {
// 当前数该位为 0,与 cnt1 个 1 异或为 1
total += cnt1 * (1LL << b);
}
}
ans = max(ans, total);
}

cout << ans << '\n';
}

// 暴力
void solve1() {
cin >> n;
vector<int> a(n);
for (auto &x : a) cin >> x;

int res = 0;
for (int i = 0; i < n; ++i) {
int cur = 0;
for (int j = 0; j < n; ++j) {
cur += (a[i] ^ a[j]);
}
res = max(res, cur);
}
cout << res << '\n';
}

int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while (t--) solve();
}