mygo场,感觉被出题人强碱了
A
展示一下python一行流(bushi
1 |
input(); print(len(list(filter(lambda x: x != 1, map(int, input().split()))))) |
L
1 2 3 4 5 |
n, x = map(int, input().split()) if n % 2 != x % 2: print(-1) else: print((n + x) // 2, (n - x) // 2) |
I
1 2 3 4 5 6 7 8 9 |
t, a, k = map(int, input().split()) l, r = 0, t if l > r: l, r = r, l l, r = l - k, r + k if l <= a <= r: print(abs(a) + abs(t - a)) else: print(abs(t) + abs(t - a) * 2) |
M
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 = 1e5 + 10; int a[N], b[N], pos[N]; template<typename T> inline void chkmin(T &a, const T &b) { if (a > b) a = b; } int solve() { int n; cin >> n; for (int i = 1; i <= n; ++ i) cin >> a[i]; for (int i = 1; i <= n; ++ i) cin >> b[i]; a[n + 1] = b[n + 1] = 0; if (n == 1) return -1; if (n == 2 and a[1] == b[1]) return -1; int flag = false; for (int i = 1; i <= n && !flag; ++ i) { if (i == 1 and a[1] == b[2]) flag = true; if (i == n and a[n] == b[n - 1]) flag = true; if (i != 1 and i != n) { for (int j = -1; j <= 1 && !flag; ++ j) if (a[i] == b[i + j]) flag = true; } } return flag ? 1 : 2; } int main() { cin.tie(0)->sync_with_stdio(0); int T; cin >> T; while (T --) cout << solve() << '\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 |
#include <bits/stdc++.h> using namespace std; using LL = long long; const int N = 1e5 + 10; int a[N], f[N]; template<typename T> inline void chkmin(T &a, const T &b) { if (a > b) a = b; } int main() { cin.tie(0)->sync_with_stdio(0); memset(f, 0x3f, sizeof f); int n; cin >> n; for (int i = 1; i <= n; ++ i) cin >> a[i]; f[1] = a[1] - 1; f[n + 1] = a[n] - 1; for (int i = 2; i <= n; ++ i) { chkmin(f[i], min(a[i - 1], a[i]) - 1); } for (int i = 1; i <= n; ++ i) { if (f[i] + f[i + 1] >= a[i]) { f[i + 1] = a[i] - 1 - f[i]; } } LL ans = 0; for (int i = 1; i <= n + 1; ++ i) ans += f[i]; cout << ans; } |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 10; int n, a[N]; int prime[N], cnt; bool st[N]; void get_primes(int n) { for (int i = 2; i <= n; ++ i) { if (!st[i]) prime[cnt ++] = i; for (int j = 0; prime[j] <= n / i; ++ j) { st[prime[j] * i] = true; if (i % prime[j] == 0) break; } } } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; get_primes(n * 2); if (n & 1) a[1] = 1; for (int idx = cnt; idx; -- idx) { int p = prime[idx]; for (int i = 1; i < p and i <= n; ++ i) { int j = p - i; if (i == j or a[i] or a[j]) continue; if (j > n) continue; a[i] = j, a[j] = i; } } bool flag = true; for (int i = 1; i <= n and flag; ++ i) if (st[a[i] + i] or !a[i]) flag = false; if (flag) { for (int i = 1; i <= n; ++ i) cout << a[i] << ' '; } else cout << -1; } |
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 |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5, M = N << 1; int n, a[N]; int prime[M], cnt; bool st[M]; void get_primes(int n) { for (int i = 2; i <= n; ++ i) { if (!st[i]) prime[cnt ++] = i; for (int j = 0; prime[j] <= n / i; ++ j) { st[prime[j] * i] = true; if (i % prime[j] == 0) break; } } } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; get_primes(n * 2); int t = 1; bool flag = false; if (n & 1) a[1] = 1, t ++; if (not st[t + n]) { flag = true; for (int i = t; i <= n; ++ i) a[i] = t + n - i; } else { for (int i = t; i < n and not flag; ++ i) { if (not st[i + t] and not st[n + 1 + i]) { for (int j = t; j <= i; ++ j) a[j] = i + t - j; for (int j = i + 1; j <= n; ++ j) a[j] = i + 1 + n - j; flag = true; } } } if (flag) for (int i = 1; i <= n; ++ i) cout << a[i] << ' '; else cout << -1; } |
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 |
#include <bits/stdc++.h> using namespace std; using LL = long long; int main() { cin.tie(0)->sync_with_stdio(0); constexpr int mod = 1e9 + 7; string s; cin >> s; int n = s.size(); vector<int> f(n + 1); f[0] = 1, f[1] = 2; for (int i = 2; i <= n; ++ i) f[i] = (f[i - 1] + f[i - 2]) % mod; const vector<string> template_strings = { "mygo", "m-ygo", "my-go", "myg-o", "m-y-go", "m-yg-o", "my-g-o", "m-y-g-o" }; int ans = 0; for (auto &template_string : template_strings) { for (int i = 0; i < n; ++ i) { if (i + template_string.size() > n) continue; auto now_string = s.substr(i, template_string.size()); bool flag = true; for (int j = 0; j < template_string.size() and flag; ++ j) { if (template_string[j] == '-') continue; if (template_string[j] != now_string[j]) flag = false; } if (flag) ans = (ans + (LL)f[i] * f[n - i - template_string.size()] % mod) % mod; } } cout << ans; } |
发表回复