先放这,后面会补的
A. Odd Selection
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, a, b) for (register int i = a; i <= b; i++) int x, n, a[1010]; int even, odd; void solve() { cin >> n >> x; odd = even = 0; rep(i, 1, n) { cin >> a[i]; if (a[i] % 2) odd++; else even++; } int flag = 1; if (x == n && odd % 2 == 0) flag = 0; if (odd == 0) flag = 0; if ((x - 1) % 2 && even == 0) flag = 0; puts(flag ? "Yes" : "No"); } int main() { int t = 1; cin >> t; while (t--) { solve(); } }
B. Subsequence Hate
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, a, b) for (register int i = a; i <= b; i++) char s[1010]; int n, dp[2][1010]; int ans; void solve() { memset(s, 0, sizeof(s)); cin >> s + 1; n = 0; for (int i = 1; s[i] != 0; i++) { n++; dp[0][i] = dp[0][i - 1]; dp[1][i] = dp[1][i - 1]; if (s[i] == '1') dp[0][i]++; if (s[i] == '0') dp[1][i]++; } ans = min(dp[0][n], dp[1][n]); for (int i = 1; s[i] != 0; i++) { ans = min(ans, dp[0][i] + dp[1][n] - dp[1][i]); ans = min(ans, dp[1][i] + dp[0][n] - dp[0][i]); } cout << ans << endl; } int main() { int t = 1; cin >> t; while (t--) { solve(); } }
C. Game On Leaves
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, a, b) for (register int i = a; i <= b; i++) int n, x; int u, v, cnt; void solve() { cin >> n >> x; cnt = 0; rep(i, 1, n - 1) { cin >> u >> v; if (u == x || v == x) cnt++; } if (cnt <= 1 || !(n & 1)) puts("Ayush"); else puts("Ashish"); } int main() { int t = 1; cin >> t; while (t--) { solve(); } }