A
简单分类讨论题,没什么意思。
#include <bits/stdc++.h>using i64 = long long;void solve() {i64 a, b;std::cin >> a >> b;if (a == 0 || b == 0) {std::cout << "Zero\n";return;}if (a > 0) {if (b > 0)std::cout << "Positive\n";elsestd::cout << "Zero\n";} else {if (b > 0)std::cout << "Zero\n";elsestd::cout << (std::abs(a - b) & 1 ? "Positive" : "Negative") << "\n";}
}int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);solve();return 0;
}
B
简单模拟题。拿桶维护一下,顺便统计一下颜色的可行性?做完了。
#include <bits/stdc++.h>using i64 = long long;void solve() {int n, m;std::cin >> n >> m;std::vector<int> cnt(n + 1, 1), clr(n + 1);int ans = 1; clr[1] = 1;for (int i = 1, x, y; i <= m; i++) {std::cin >> x >> y;cnt[y]++, cnt[x]--;if (clr[x]) {if (!clr[y])ans++;clr[y] = 1;}if (!cnt[x]) {if (clr[x]) {clr[x] = 0;ans--;}}}std::cout << ans << "\n";
}int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);solve();return 0;
}
C
贪心 pick 左右两边较小值 pop 想一想都知道很容易被 hack,套路化的,考虑转构造为判定。只有剩下最后两段绳子的长度 \(\geq l\) 才会有解,找到这两段绳子然后从两端向中间 pop 记录答案就可以了。
#include <bits/stdc++.h>using i64 = long long;void solve() {int n, k;std::cin >> n >> k;std::vector<int> a(n + 1);for (int i = 1; i <= n; i++) {std::cin >> a[i];}for (int i = 1; i < n; i++) {if (a[i] + a[i + 1] >= k) {std::cout << "Possible\n";for (int j = 1; j < i; j++)std::cout << j << "\n";for (int j = n; j >= i + 2; j--)std::cout << j - 1 << "\n";std::cout << i << "\n";return;}}std::cout << "Impossible\n";
}int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);solve();return 0;
}