我为什么这么菜?蒟蒻想变强。
A
1 2 |
a, b, k = map(int, input().split()) print('good' if a >= k * b else 'bad') |
B
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); int n, sum = 0; cin >> n; for (int i = 1; i <= n; ++ i) { int x; cin >> x; x --; sum = (sum + x % 2) % 2; } cout << (sum ? "gui" : "sweet") << '\n'; } |
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 |
#include <bits/stdc++.h> using namespace std; constexpr int N = 110; char s[N][N]; int op[N], z[N]; void move1(int n, int m, int z) { // right move char tmp = s[z][m]; for (int i = m; i >= 2; -- i) s[z][i] = s[z][i - 1]; s[z][1] = tmp; } void move2(int n, int m, int z) { // down move char tmp = s[n][z]; for (int i = n; i >= 2; -- i) s[i][z] = s[i - 1][z]; s[1][z] = tmp; } int main() { cin.tie(0)->sync_with_stdio(0); int n, m, x, y; cin >> n >> m >> x >> y; for (int i = 1; i <= n; ++ i) cin >> (s[i] + 1); int p, q; cin >> p >> q; for (int i = 1; i <= q; ++ i) cin >> op[i] >> z[i]; for (int i = 1; i <= p; ++ i) { for (int i = 1; i <= q; ++ i) { if (op[i] == 1) move1(n, m, z[i]); else move2(n, m, z[i]); } } cout << s[x][y] << '\n'; } |
D
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 |
#include <bits/stdc++.h> using namespace std; using LL = long long; constexpr int N = 2e5 + 10; int a[N]; int main() { cin.tie(0)->sync_with_stdio(0); int n; LL sum = 0; cin >> n; for (int i = 1; i <= n; ++ i) { cin >> a[i]; sum += (LL)a[i]; } if (n == 1) { cout << 1 << '\n'; return 0; } int ans = 0; for (LL i = 1; i <= sum / i; ++ i) { if (sum % i != 0) continue; LL a = sum / i, b = i; if (a == b) { if (a >= n) ans ++; } else { if (a >= n) ans ++; if (b >= n) ans ++; } } cout << ans << '\n'; } |
E
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 |
#include <bits/stdc++.h> using namespace std; using LL = long long; using PII = pair<int, int>; constexpr int N = 2e5 + 10; int a[N], b[N]; int main() { cin.tie(0)->sync_with_stdio(0); int n, k; cin >> n >> k; map<int, vector<int>> m; for (int i = 1; i <= n; ++ i) { cin >> a[i]; a[i] %= k; b[i] = (b[i - 1] + a[i]) % k; } for (int i = 0; i <= n; ++ i) { m[b[i]].push_back(i); } vector<PII> segs; for (auto &[num, v]: m) { if (v.size() <= 1) continue; for (int i = 1; i < v.size(); ++ i) { segs.push_back({v[i - 1] + 1, v[i]}); } } sort(segs.begin(), segs.end()); int maxR = -2e9, res = 0; for (auto &[l, r]: segs) { if (l <= maxR) maxR = min(maxR, r); else res ++, maxR = r; } cout << res << '\n'; } |
G
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 |
#include <bits/stdc++.h> using namespace std; constexpr int N = 510; char s[N][N]; int b[N][N]; int main() { cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; ++ i) cin >> (s[i] + 1); for (int i = 1; i <= n; ++ i) for (int j = 1; j <= m; ++ j) b[i][j] = b[i][j - 1] + (s[i][j] == '*'); int ans = 0; for (int i = 1; i <= n; ++ i) for (int j = 1; j <= m; ++ j) if (s[i][j] == '*') for (int l = j - 1, r = j + 1, h = i + 1; l > 0 and r <= m and h <= n and s[h][l] == '*' and s[h][r] == '*'; -- l, ++ r, ++ h) if (b[h][r] - b[h][l - 1] == r - l + 1) ans ++; cout << ans << '\n'; } |
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
#include <bits/stdc++.h> template<typename T> inline void chkmax(T &a, const T &b) { if (a < b) a = b; } void solve() { int n; std::cin >> n; /** * f[i]表示对于前i个数 * 选择了第i个数 * 总共选择了6的倍数的个数的数 * 的最大值 * * f[i]=\max {f[j]+w(j+1,i)} for j in [1,i) * w(i,j)表示在区间[i,j]中选择6个数 * 所表示的最大值 */ std::vector<int> a(n + 1), f(n + 1, 0); for (int i = 1; i <= n; ++ i) std::cin >> a[i]; auto fix2max = [&](std::set<int> &s) { while (s.size() > 1) s.erase(s.begin()); }; auto fix2min = [&](std::set<int> &s) { while (s.size() > 1) s.erase(--s.end()); }; for (int i = 1; i <= n; ++ i) { std::vector<std::set<int>> minValSet(6), maxValSet(6); /** * set[i]表示选了i+1个数的最值 i\in [0,4] * * ((b1-b2)*b3-b4)*b5-b6 */ for (int j = i; j <= n; ++ j) { // 已经选择了5个数 // 需要更新f[j] for (auto &k : maxValSet[5]) chkmax(f[j], f[i - 1] + k - a[j]); for (auto &k : minValSet[5]) chkmax(f[j], f[i - 1] + k - a[j]); // 已经选择了4个数 // 需要用set[4]更新set[5] for (auto &k : maxValSet[4]) { maxValSet[5].insert(k * a[j]); minValSet[5].insert(k * a[j]); } for (auto &k : minValSet[4]) { maxValSet[5].insert(k * a[j]); minValSet[5].insert(k * a[j]); } // 选了3个数 for (auto &k : maxValSet[3]) { maxValSet[4].insert(k - a[j]); minValSet[4].insert(k - a[j]); } for (auto &k : minValSet[3]) { maxValSet[4].insert(k - a[j]); minValSet[4].insert(k - a[j]); } // 选择了2个数 for (auto &k : maxValSet[2]) { maxValSet[3].insert(k * a[j]); minValSet[3].insert(k * a[j]); } for (auto &k : minValSet[2]) { maxValSet[3].insert(k * a[j]); minValSet[3].insert(k * a[j]); } // 选择了1个数 for (auto &k : maxValSet[1]) { maxValSet[2].insert(k - a[j]); minValSet[2].insert(k - a[j]); } for (auto &k : minValSet[1]) { maxValSet[2].insert(k - a[j]); minValSet[2].insert(k - a[j]); } maxValSet[1].insert(a[j]); minValSet[1].insert(a[j]); std::for_each(maxValSet.begin() + 1, maxValSet.end(), fix2max); std::for_each(minValSet.begin() + 1, minValSet.end(), fix2min); } } int res = 0; for (int i = 1; i <= n; ++ i) chkmax(res, f[i]); std::cout << res << '\n'; } int main() { std::cin.tie(0)->sync_with_stdio(0); solve(); } |
发表回复