A
读错提了, A, B都是从1开始
int main() {
IOS; ll n;__int128 a = 3; cin >> n;
for (int i = 1, j = 1; a < n; ++i, a *= 3, j = 1) {
__int128 b = 5;
for (; a + b < n; ++j, b *= 5);
if (a + b == n) {
cout << i << ' ' << j; return 0;
}
}
cout << -1;
return 0;
}
B
在连通分量内, 总差值和为0就行
int n, m, _, k;
int f[N];
ll a[N], b[N], s[N];
int find(int x) {
return x == f[x] ? x : f[x] = find(f[x]);
}
void unit(int x, int y) {
x = find(x), y = find(y);
if (x == y) return;
f[y] = x, s[x] += s[y];
}
int main() {
IOS; cin >> n >> m;
rep (i, 1, n) cin >> a[i], f[i] = i;
rep (i, 1, n) cin >> b[i], s[i] = a[i] - b[i];
rep (i, 1, m) {
int u, v; cin >> u >> v;
unit(u, v);
}
bool g = 1;
rep (i, 1, n) if (i == f[i] && s[i]) g = 0;
if (g) cout << "Yes";
else cout << "No";
return 0;
}
C
分情况讨论
int main() {
IOS; cin >> n >> m;
if ((m < 0 || m > n - 2) && m != 0) { cout << -1 << '
'; return 0; }
if (m) {
cout << 1 << ' ' << 2 + (m + 1 << 1) << '
';
rep (i, 1, m + 1) cout << i * 2 << ' ' << i * 2 + 1 << '
';
rep (i, 1, n - m - 2) cout << 1 + (m + 1 << 1) + i * 2 << ' ' << 2 + (m + 1 << 1) + i * 2 << '
';
} else {
rep (i, 1, n) cout << -1 + i * 2 << ' ' << i * 2 << '
';
}
return 0;
}