红温场,破防了
A
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=67184952
水,但是题目看错Wa了一发
1 2 3 4 5 6 7 |
for _ in range(int(input())): a, b = map(str, input().split()) if a[0].upper() == b[0].upper(): print("Yes") else: print("No") |
L
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=67186292
水
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
n = int(input()) a = list(map(int, input().split())) ans = 0 def check(i, j): num = int(str(i) + str(j)) return num % 36 == 0 for i in range(n): for j in range(n): if i != j and check(a[i], a[j]): ans += 1 print(ans) |
D
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=67191409
注意数据范围,暴力即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#include <bits/stdc++.h> using namespace std; using LL = long long; constexpr int N = 1e3 + 10; int a[N]; LL b[N]; template<typename T> void chkmin(T &a, const T &b) { if (a > b) a = b; } template<typename T> void chkmax(T &a, const T &b) { if (a < b) a = b; } LL calc(int n) { LL res = -2e18; set<LL> st; st.insert(0); for (int i = 1; i <= n; ++ i) { b[i] = b[i - 1] + a[i]; chkmax(res, b[i] - *st.begin()); st.insert(b[i]); } return res; } int main() { cin.tie(0)->sync_with_stdio(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; ++ i) { cin >> a[i]; } LL ans = calc(n); if (k == 1) { for (int i = 1; i < n; ++ i) { swap(a[i], a[i + 1]); chkmax(ans, calc(n)); swap(a[i], a[i + 1]); } } cout << ans << '\n'; } |
B
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=67194817
猜结论
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <bits/stdc++.h> using namespace std; constexpr int N = 30; int a[N]; void solve() { int n; cin >> n; for (int i = 1; i <= n; ++ i) cin >> a[i]; cout << (n & 1 ? "qcjj": "zn") << '\n'; } int main() { cin.tie(0)->sync_with_stdio(0); int T; cin >> T; while (T --) solve(); } |
M
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=67199863
注意到mod=36很小,直接暴力枚举就好
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include <bits/stdc++.h> using namespace std; using LL = long long; constexpr int N = 1e5 + 10, M = 40, mod = 36; LL a[N]; int cnt[M]; int n; int len(LL x) { int res = 0; for (; x; x /= 10) res ++; return res; } int fpow(int a, int b, int mod) { int res = 1; for (; b; b >>= 1) { if (b & 1) res = (LL)res * a % mod; a = (LL)a * a % mod; } return res; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++ i) { cin >> a[i]; cnt[a[i] % mod] ++; } LL ans = 0; for (int i = 1; i <= n; ++ i) { int c = fpow(10, len(a[i]), mod); int b = a[i] % mod; for (int j = 0; j < mod; ++ j) { if ((j * c + b) % mod == 0) { ans += cnt[j] - (j == b); } } } cout << ans << '\n'; } |
G
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=67204116
分类讨论所有的情况就可以
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <bits/stdc++.h> using namespace std; bool solve() { int n; cin >> n; vector<int> x(n), y(n), z(n); int flag = false; for (int i = 0; i < n; ++ i) { cin >> x[i] >> y[i] >> z[i]; if (x[i] == y[i] && z[i]) flag = true; } if (flag) return false; if (n == 1) return true; if (x[0] == x[1] && y[0] == y[1] && z[0] != z[1]) return false; if (x[0] == y[1] && y[0] == x[1] && z[0] == z[1] && z[1]) return false; return true; } int main() { cin.tie(0)->sync_with_stdio(0); int T; cin >> T; while (T --) { if (solve()) cout << "Yes\n"; else cout << "No\n"; } } |
H
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=67214041
注意到只有三个数,暴力枚举就好
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#include <bits/stdc++.h> using namespace std; using Tp = tuple<int, int, int>; using PII = pair<int, int>; bool solve() { int n; cin >> n; vector<Tp> v(n); for (auto &[x, y, z]: v) { cin >> x >> y >> z; } vector<int> t(5); auto check = [&](vector<int> &a, vector<Tp> &b) -> bool { for (auto [x, y, z]: b) { if ((a[x] < a[y]) != z) return false; } return true; }; for (int i = 0; i < 3; ++ i) for (int j = 0; j < 3; ++ j) for (int k = 0; k < 3; ++ k) { t[1] = i, t[2] = j, t[3] = k; if (check(t, v)) return true; } return false; } int main() { cin.tie(0)->sync_with_stdio(0); int T; cin >> T; while (T --) { if (solve()) cout << "Yes\n"; else cout << "No\n"; } } |
J
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=67220105
对于每一个点,计算一下他被取到的概率,求和就好
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#include <bits/stdc++.h> using namespace std; using LD = long double; constexpr int N = 2e5 + 10; vector<int> e[N]; void add(int a, int b) { e[a].push_back(b); } int main() { cin.tie(0)->sync_with_stdio(0); int n, m, k; cin >> n >> m >> k; LD ans1 = 0, ans2 = 0; for (int i = 1; i <= k; ++ i) { int u, v; cin >> u >> v; add(u, v + n); add(v + n, u); } for (int i = 1; i <= n; ++ i) { int u = i; LD t = 1; for (auto to: e[u]) { int siz = e[to].size(); t *= (LD)(siz - 1) / siz; } ans1 += 1 - t; } for (int i = n + 1; i <= n + m; ++ i) { int v = i; LD t = 1; for (auto to: e[v]) { int siz = e[to].size(); t *= (LD)(siz - 1) / siz; } ans2 += 1 - t; } cout << "float\n"; cout << fixed << setprecision(10) << ans1 << ' '; cout << fixed << setprecision(10) << ans2; } |
K
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
#include <iostream> #include <cstring> #include <algorithm> #include <queue> using namespace std; using PII = pair<int, int>; void solve() { int a, b; cin >> a >> b; if (a % 2 == 0 || b % 2 == 1) { cout << "No\n"; return; } queue<PII> q; vector<PII> ans(a + b + 1, {-1, -1}); int idx = 0, cnt = a + b; q.push({++ idx, 0}); a --; while (q.size()) { auto [id, col] = q.front(); q.pop(); if (col) { // red point, need black if (a > 1) { q.push({++ idx, 0}); ans[id].first = idx; q.push({++ idx, 0}); ans[id].second = idx; a -= 2; } } else { if (b > 1) { q.push({++ idx, 1}); ans[id].first = idx; q.push({++ idx, 1}); ans[id].second = idx; b -= 2; } } } if (a > 0 || b > 0) { cout << "No\n"; return; } cout << "Yes\n"; for (int i = 1; i <= cnt; ++ i) { auto [l, r] = ans[i]; cout << l << ' ' << r << '\n'; } } int main() { cin.tie(0)->sync_with_stdio(0); int T; cin >> T; while (T --) solve(); } |
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
#include <bits/stdc++.h> using namespace std; constexpr int N = 1e5 + 10; bool pre[N], suf[N]; void calc(string &s, int n, bool *pre) { vector<int> d1(n); for (int i = 0, l = 0, r = -1; i < n; i++) { int k = (i > r) ? 1 : min(d1[l + r - i], r - i + 1); while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) { k++; } d1[i] = k--; if (i + k > r) { l = i - k; r = i + k; } } vector<int> d2(n); for (int i = 0, l = 0, r = -1; i < n; i++) { int k = (i > r) ? 0 : min(d2[l + r - i + 1], r - i + 1); while (0 <= i - k - 1 && i + k < n && s[i - k - 1] == s[i + k]) { k++; } d2[i] = k--; if (i + k > r) { l = i - k - 1; r = i + k; } } for (int i = 0; i < n; ++ i) { int l = i - d1[i] + 1, r = i + d1[i] - 1; if (!l && !pre[r]) pre[r] = true; l = i - d2[i], r = i + d2[i] - 1; if (!l && !pre[r]) pre[r] = true; } } int main() { cin.tie(0)->sync_with_stdio(0); int n, m; string s, t; cin >> n >> m >> s >> t; if (n > m) swap(s, t), swap(n, m); calc(s, n, suf); reverse(s.begin(), s.end()); calc(s, n, pre); int pre_same = -1; for (int i = 0; i < n; ++ i) { if (s[i] != t[i]) break; pre_same = i; } int suf_same = n; for (int i = 0; i < n; ++ i) { if (s[n - 1 - i] != t[m - 1 - i]) break; suf_same = n - i - 1; } vector<int> L, R; for (int i = 0; i < n; ++ i) { int j = n - 1 - i; if (pre[i] && i <= pre_same) L.push_back(i); if (suf[j] && i >= suf_same) R.push_back(i); } int ans = -1; for (auto left: L) { auto it = upper_bound(R.begin(), R.end(), left); if (it != R.end()) { int right = *it; if (left < right) { ans = max(ans, n - right + left + 1); } } } if (~ans) ans <<= 1; cout << ans << '\n'; } |
发表回复