总体情况:考场上切了 a − e a - e a−e,拿到不错的排名,但是后两题还是很难理解(捂脸
A
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, t, a;
cin >> n >> t >> a;
n = n - t - a;
if (n + t < a || n + a < t) cout << "Yes";
else cout << "No";
}
B
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e2 + 10;
int n, m;
char s[maxn][maxn];
int a[maxn];
string t[maxn];
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> s[i], m = max(m, (int)(strlen(s[i])));
for (int i = 0; i < m; ++i) {
string t = "";
for (int j = n; j >= 1; --j) {
if (s[j][i]) t = t + s[j][i];
else t = t + '*';
}
int f = -1;
for (int i = t.size() - 1; i >= 0; --i) {
if (t[i] != '*') {
f = i;
break;
}
}
for (int i = 0; i <= f; ++i) cout << t[i];
cout << '\n';
}
}
C
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e6 + 10;
int q;
int c[maxn];
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> q;
int ans = 0;
for (int i = 1, op, x; i <= q; ++i) {
cin >> op;
if (op == 1) {
cin >> x;
if (!c[x]) ans++;
c[x]++;
} else if (op == 2) {
cin >> x;
if (c[x] == 1) ans--;
c[x]--;
} else cout << ans << '\n';
}
}
D
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e2 + 10;
int n, m;
int a[maxn][maxn][maxn], s[maxn][maxn][maxn];
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
for(int k = 1; k <= n; ++k) {
cin >> a[i][j][k];
s[i][j][k] = a[i][j][k] + s[i][j][k - 1] + s[i][j - 1][k] +
s[i - 1][j][k] - s[i][j - 1][k - 1] - s[i - 1][j][k - 1] -
s[i - 1][j - 1][k] + s[i - 1][j - 1][k - 1];
}
cin >> m;
for(int i = 1, lx, rx, ly, ry, lz, rz; i <= m; ++i) {
cin >> lx >> rx >> ly >> ry >> lz >> rz;
cout << s[rx][ry][rz] - s[lx - 1][ry][rz] - s[rx][ly - 1][rz] -
s[rx][ry][lz - 1] + s[lx - 1][ly - 1][rz] + s[lx - 1][ry][lz - 1] +
s[rx][ly - 1][lz - 1] - s[lx - 1][ly - 1][lz - 1] << '\n';
}
}
E
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 5e6 + 10, K = 2.5e6;
int n, m;
int a[maxn], b[maxn];
int c[maxn], d[maxn];
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1, x, y; i <= n; ++i) {
cin >> x >> y;
x += K, y += K;
a[x]++, b[y]++;
c[1] += x - 1, d[1] += y - 1;
}
for (int i = 1; i < maxn; ++i) a[i] += a[i - 1], b[i] += b[i - 1];
for (int i = 2; i < maxn; ++i) {
c[i] = c[i - 1] + a[i - 1] * 2 - n;
d[i] = d[i - 1] + b[i - 1] * 2 - n;
}
sort (c + 1, c + maxn);
sort (d + 1, d + maxn);
int ans = 0;
for (int i = 1, j = maxn - 1; i < maxn; ++i) {
while (j > 0 && c[i] + d[j] > m) j--;
ans += j;
}
cout << ans << '\n';
}
F
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 10, maxm = 20;
struct node {
int x, y;
}a[maxn];
int n, k;
int f[maxn][maxm];
bool cmp(node x, node y) {
return (x.x - 1) * y.y < (y.x - 1) * x.y;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> a[i].x >> a[i].y;
sort(a + 1, a + n + 1, cmp);
f[0][0] = 1;
for (int i = 1; i <= n; ++i) {
f[i][0] = f[i - 1][0];
for (int j = 1; j <= k; ++j)
f[i][j] = max(f[i - 1][j], a[i].x * f[i - 1][j - 1] + a[i].y);
}
cout << f[n][k] << '\n';
}
G
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e2 + 10;
int n, m;
int a[maxn], b[maxn];
bool vis[maxn];
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1, u, v; i <= m; ++i) {
cin >> u >> v;
u--, v--;
a[u] += (1ll << v);
a[v] += (1ll << u);
}
for (int i = 0; i < n; ++i) {
for (int j = n - 1; j >= 0; --j) if ((a[i] >> j) & 1) {
if (!b[j]) {
b[j] = a[i];
break;
} else a[i] ^= b[j];
}
}
for (int i = 0; i < n; ++i) a[i] = (1ll << i);
for (int i = 0; i < n; ++i) if (b[i]) {
a[i] = 0;
for (int j = 0; j < i; ++j) if ((b[i] >> j) & 1) a[i] ^= a[j];
if (!a[i]) {
cout << "No\n";
return 0;
}
}
cout << "Yes\n";
for (int i = 0; i < n; ++i) cout << a[i] << ' ';
cout << '\n';
}
以上为所有题目的代码参考,如有疑问请私信。