AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; void Solve() { string s; cin >> s; if ((s[0] == 'Y' || s[0] == 'y') && (s[1] == 'e' || s[1] == 'E') && (s[2] == 's' || s[2] == 'S')) { cout << "YES\n"; } else { cout << "NO\n"; } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; void Solve() { int len; cin >> len; string s; cin >> s; int ans = 0; vector<bool> vis(26, 0); for (int i = 0; i < len; i++) { if (!vis[s[i] - 'A']) { vis[s[i] - 'A'] = true; ans += 2; } else { ans++; } } cout << ans << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; void Solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int j = 0; j < n; j++) { int m; string s; cin >> m >> s; for (int i = 0; i < m; i++) { if (s[i] == 'D') { a[j] = (a[j] + 1) % 10; } else { a[j] = (a[j] + 9) % 10; } } } for (int i = 0; i < n; i++) { cout << a[i] << " \n"[i == n - 1]; } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; void Solve() { int n; cin >> n; vector<string> a(n); map<string, int> mp1, mp2; string ans = ""; for (int i = 0; i < n; i++) { cin >> a[i]; mp1[a[i]] = 1; string two = a[i] + a[i]; mp2[two] = 1; } for (int i = 0; i < n; i++) { string s1 = "", s2 = ""; int len = a[i].size(); bool ok = false; if (mp2[a[i]] == 1) { ok = true; } for (int j = 0; j < len - 1; j++) { s1 = a[i].substr(0, j + 1); s2 = a[i].substr(j + 1, len - 1); if (mp1[s1] == 1 && mp1[s2] == 1) { ok = true; } } if (ok) { ans += '1'; } else { ans += '0'; } } cout << ans << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; void Solve() { int n; cin >> n; vector<string> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } LL ans = 0; if (n & 1) { for (int i = 0; i < n / 2; i++) { for (int j = 0; j < n / 2; j++) { int cnt0 = 0, cnt1 = 0; if (a[i][j] == '0') { cnt0++; } else { cnt1++; } if (a[j][n - i - 1] == '0') { cnt0++; } else { cnt1++; } if (a[n - i - 1][n - j - 1] == '0') { cnt0++; } else { cnt1++; } if (a[n - j - 1][i] == '0') { cnt0++; } else { cnt1++; } ans += min(4 - cnt0, 4 - cnt1); } } for (int j = 0; j < n / 2; j++) { int cnt0 = 0, cnt1 = 0; if (a[n / 2][j] == '0') { cnt0++; } else { cnt1++; } if (a[j][n - n / 2 - 1] == '0') { cnt0++; } else { cnt1++; } if (a[n - n / 2 - 1][n - j - 1] == '0') { cnt0++; } else { cnt1++; } if (a[n - j - 1][n / 2] == '0') { cnt0++; } else { cnt1++; } ans += min(4 - cnt0, 4 - cnt1); } } else { for (int i = 0; i < n / 2; i++) { for (int j = 0; j < n / 2; j++) { int cnt0 = 0, cnt1 = 0; if (a[i][j] == '0') { cnt0++; } else { cnt1++; } if (a[j][n - i - 1] == '0') { cnt0++; } else { cnt1++; } if (a[n - i - 1][n - j - 1] == '0') { cnt0++; } else { cnt1++; } if (a[n - j - 1][i] == '0') { cnt0++; } else { cnt1++; } ans += min(4 - cnt0, 4 - cnt1); } } } cout << ans << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; LL a[200010], tree[200010]; int n; int lowbit(int x) { return x & -x; } LL getsum(int x) { LL res = 0; for (int i = x; i > 0; i -= lowbit(i)) { res += tree[i]; } return res; } void update(int x, int v) { for (int i = x; i <= n; i += lowbit(i)) { tree[i] += v; } } void Solve() { cin >> n; LL ans = 0; memset(tree, 0, sizeof(tree)); for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = n; i >= 1; i--) { if (i > a[i]) { ans += getsum(n) - getsum(i + 1); update(a[i] + 1, 1); } } cout << ans << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; void Solve() { int n; LL k; cin >> n >> k; vector<LL> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } LL ans = -0x3f3f3f3f; LL sum = 0; for (int i = 0; i < n; i++) { LL s = 0; for (int j = 0; j <= 32; j++) { if (i + j > n - 1) { break; } s += a[i + j] >> (j + 1); } ans = max(ans, sum + s); sum += a[i] - k; } cout << max(ans, sum) << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }
Codeforces Round #806 (Div. 4)(7/7)
最新推荐文章于 2024-09-11 19:54:50 发布
关键词由CSDN通过智能技术生成