太菜了太菜了 根本写不来 orz
什么情况?
keyboard_arrow_down
题目 A B C D E F G H I J K L M | 总计
状态 1 1 1 - - - - 1 1 - 1 1 1 | 8
A 欢迎来到第五届兰州大学第五届程序设计大赛校赛
1 |
print(45) |
B 小凯的疑惑
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 |
#include <iostream> #include <cstring> #include <vector> #include <algorithm> using namespace std; const int N = 2e5 + 10; int a[N]; bool vis[N]; int main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; for (int i = 1; i <= n; ++ i) { cin >> a[i]; } int ans = 0; for (int i = 1; i <= n; ++ i) { if (vis[i]) continue; int p = i, cnt = 0; bool has1 = false, has2 = false; do { cnt ++; vis[p] = true; if (a[p] == 1) has1 = true; if (a[p] == 2) has2 = true; p = a[p]; } while (p != i); if (cnt == 1) continue; if (cnt == 2 && !has1 && has2) { ans += 2; } else { if (has1) ans += cnt - 1; else ans += cnt + 1; } } cout << ans; } |
C 走过路过不要错过
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 5e3 + 10; bool st[N]; int main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; int ans = 0; while (n --) { int x; cin >> x; if (!st[x]) { st[x] = true; ans ++; } } cout << ans << endl; } |
D Ball
1 |
// orz |
E 数问题
打个表先
正解写不出来
F 光叶子花
1 |
// orz |
G Palindrome
1 |
// orz |
H 青青草原
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 |
#include <iostream> #include <cstring> #include <algorithm> using namespace std; using piii = pair<pair<int, int>, int>; const int N = 2e5 + 10; piii a[N]; int ans[N], tr[N]; int n; int find_right(int x) { // 查找小于等于x的最后一个元素 int l = 1, r = n; while (l < r) { int mid = l + r + 1 >> 1; if (a[mid].first.first > x) r = mid - 1; else l = mid; } return l; } int lowbit(int x) { return x & -x; } void add(int x, int v) { for (; x < N; x += lowbit(x)) tr[x] += v; } int query(int x) { int res = 0; for (; x; x -= lowbit(x)) res += tr[x]; return res; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++ i) { cin >> a[i].first.first >> a[i].first.second; a[i].second = i; } sort(a + 1, a + 1 + n, [](piii &a, piii &b) -> bool { if (a.first.first != b.first.first) return a.first.first < b.first.first; return a.second < b.second; }); for (int i = 1; i <= n; ++ i) { // 对于i之后的元素查找l在a[i]中的元素-二分 // 对于i之前的元素查找r在a[i]中的元素-树状数组 int r = find_right(a[i].first.second) - i; int l = query(2e5) - query(a[i].first.first - 1); ans[a[i].second] = r + l + 1; add(a[i].first.second, 1); } for (int i = 1; i <= n; ++ i) { cout << ans[i]; if (i != n) cout << ' '; } } |
I 涂颜色
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 |
#include <iostream> #include <cstring> #include <algorithm> using namespace std; using LL = long long; const int mod = 998244353; const int N = 1e5 + 10; int f[N]; int fpow(int a, int b) { int res = 1; for (; b; b >>= 1) { if (b & 1) res = (LL)res * a % mod; a = (LL)a * a % mod; } return res; } int main() { int n, m; cin >> n >> m; for (int i = 2; i <= n; ++ i) { f[i] = ((LL)m * fpow(m - 1, i - 1) - f[i - 1]) % mod; f[i] = (f[i] + mod) % mod; } cout << f[n]; } |
J 洋片箱
1 |
// orz |
K 7etris!
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; int main() { cin.tie(0)->sync_with_stdio(0); cout.tie(0); int n, m; bool flag = false; // 是否失败 cin >> n >> m; int cnt = 0; vector<vector<char>> s(21, vector<char>(m + 1, '.')); auto down = [&](string typ, int r, int x) -> void { pair<int, int> shape; if (typ == "O") shape = {2, 2}; else if (r & 1) shape = {1, 4}; else shape = {4, 1}; // find endpos int endpos = 20, hight = shape.first, width = shape.second; for (int i = 1; i <= 20 && endpos == 20; ++ i) { bool f = true; for (int j = x; j < x + width && f; ++ j) { if (s[i][j] != '.') { f = false; endpos = i - 1; } } } int notfinish = hight; // down for (int i = endpos; i > endpos - hight && i > 0; -- i, -- notfinish) { for (int j = x; j < x + width; ++ j) { s[i][j] = typ[0]; } } // remove && down for (int i = 20; i;) { int f = true; // 需要清除本行 for (int j = 1; j <= m && f; ++ j) if (s[i][j] == '.') f = false; if (f) { for (int j = i; j; -- j) for (int k = 1; k <= m; ++ k) s[j][k] = s[j - 1][k]; // 补上没完成的部分 if (notfinish) { for (int j = x; j < x + width; ++ j) { s[1][j] = typ[0]; } notfinish --; } } else i --; } if (notfinish) flag = true; else cnt ++; }; for (int i = 1; i <= n && !flag; ++ i) { string typ; int r, x; cin >> typ >> r >> x; down(typ, r, x); } cout << cnt << '\n'; for (int i = 1; i <= 20; ++ i, cout << '\n') for (int j = 1; j <= m; ++ j) cout << s[i][j]; } |
L 简单数组
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 |
#include <iostream> #include <cstring> #include <algorithm> using namespace std; using LL = long long; const int mod = 1e9 + 7; const int N = 2e5 + 10; int h[N], a[N], s[N]; void init() { for (int i = 2; i < N; ++ i) { a[i] = ((LL)s[i - 1] + h[i - 1]) % mod; s[i] = ((LL)s[i - 1] + a[i]) % mod; h[i] = ((LL)h[i - 1] * a[i]) % mod; } } int main() { cin.tie(0)->sync_with_stdio(0); int T; cin >> T >> a[1]; s[1] = h[1] = a[1]; init(); while (T --) { int x; cin >> x; cout << a[x] << endl; } } |
M 沼泽人
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <iostream> #include <cstring> #include <algorithm> using namespace std; int main() { int n, k, m; cin >> n >> k >> m; int t = n / k; if (m % k == 0) { cout << t - 1; } else { cout << t + (t * k + m % k <= n) - 1; } } |
发表回复