明天有空就写题解,不得不说
C
S
D
N
CSDN
CSDN 的界面越来越拉了
A. Red Versus Blue
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t -- ) {
int n, r, b;
cin >> n >> r >> b;
while (b) {
int cnt = r / (b + 1);
for (int i = 1; i <= cnt; i ++ )
cout << "R";
cout << "B";
b --;
r -= cnt;
}
for (int i = 1; i <= r; i ++ )
cout << "R";
cout << endl;
}
return 0;
}
B. Bit Flipping
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
typedef vector<int> VI;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t -- ) {
int n, k;
cin >> n >> k;
string str;
cin >> str;
int tmp = 0;
VI ans, res;
for (int i = 0; i < str.size(); i ++ ) {
if (i != str.size() - 1) {
if (str[i] == '0') {
if (k & 1) {
ans.PB(1);
res.PB(0);
}
else if (tmp < k) {
ans.PB(1);
res.PB(1);
tmp ++;
} else {
ans.PB(0);
res.PB(0);
}
} else {
if ((k & 1) && (tmp < k)) {
ans.PB(1);
res.PB(1);
tmp ++;
} else if ((k & 1)) {
ans.PB(0);
res.PB(0);
}
else {
ans.PB(1);
res.PB(0);
}
}
} else {
if (tmp & 1) {
ans.PB((str[i] - '0') ^ 1);
} else ans.PB(str[i] - '0');
res.PB(k - tmp);
}
}
for (auto t : ans) cout << t;
cout << endl;
for (auto t : res)
cout << t << ' ';
cout << endl;
}
return 0;
}
C. Line Empire
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL LNF = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5 + 10;
int x[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t -- ) {
int n, a, b;
cin >> n >> a >> b;
LL num = LNF;
LL sum = 0;
for (int i = 1; i <= n; i ++ ) {
cin >> x[i];
sum += x[i];
}
LL res = 0;
for (int i = 1; i <= n; i ++ ) {
res += x[i];
num = min(num, 1ll * b * x[i] + 1ll * a * x[i]
+ 1ll * (sum - res) * b - 1ll * b * (n - i) * x[i]);
}
num = min(num, b * sum);
cout << num << endl;
}
return 0;
}
D. Reverse Sort Sum
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int c[N], a[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t -- ) {
int n;
cin >> n;
LL sum = 0;
for (int i = 0; i < n; i ++ )
cin >> c[i];
for (int i = 0; i < n; i ++ ) a[i] = 1;
for (int i = 0; i < n; i ++ ) {
if (c[i] == 0) a[i] = 0;
else if (c[i] < n) a[c[i]] = 0, c[c[i]] += c[i];
}
for (int i = 0; i < n; i ++ ) cout << a[i] << ' ';
cout << endl;
}
return 0;
}