A - Tiny Arithmetic Sequence

水题,判断3个数是否能构成等差数列

  1. void solve() {
  2. int a, b, c;
  3. cin >> a >> b >> c;
  4. if (a + b == 2 * c || a + c == 2 * b
  5. || b + c == 2 * a)cout << "Yes\n";
  6. else cout << "No\n";
  7. }

B - Do you know the second highest mountain?

排序,先按山脉高度排序,高度一样则按名字排序

  1. struct node {
  2. string s; int t;
  3. };
  4. vector<node>v;
  5. bool cmp(node a, node b) {
  6. if (a.t == b.t)return a.s > b.s;
  7. return a.t > b.t;
  8. }
  9. void solve() {
  10. int n;
  11. cin >> n;
  12. for (int i = 0; i < n; ++i) {
  13. string s; int t;
  14. cin >> s >> t;
  15. v.push_back({s, t});
  16. }
  17. sort(v.begin(), v.end(), cmp);
  18. cout << v[1].s << '\n';
  19. }

赛后发现自己写复杂化了

  1. pair<int, string>a[1010];
  2. void solve() {
  3. int n;
  4. cin >> n;
  5. for (int i = 1; i <= n; ++i)cin >> a[i].second >> a[i].first;
  6. sort(a + 1, a + 1 + n);
  7. cout << a[n - 1].second << endl;
  8. }

C - Secret Number

这道题,是检测 0000 ~ 9999 的每一个值,但我们可以通过高桥的字符串进行简化

  1. void solve() {
  2. string s; cin >> s;
  3. int ans = 0;
  4. for (int i = 0; i <= 9999; ++i) {
  5. vector<bool> f(10);
  6. int x = i;
  7. for (int j = 0; j < 4; ++j) {
  8. f[x % 10] = true;
  9. x /= 10;
  10. }
  11. bool f2 = true;
  12. for (int j = 0; j < 10; ++j) {
  13. if (s[j] == 'o' and !f[j]) f2 = false;
  14. if (s[j] == 'x' and f[j]) f2 = false;
  15. }
  16. ans += f2;
  17. }
  18. cout << ans << '\n';
  19. }
  1. S = input()
  2. ans = 0
  3. for i in range(10000):
  4. flag = [False]*10
  5. now = i
  6. for j in range(4):
  7. flag[now%10] = True
  8. now //= 10
  9. flag2 = True
  10. for j in range(10):
  11. if S[j] == 'o' and not flag[j]:
  12. flag2 = False
  13. if S[j] == 'x' and flag[j]:
  14. flag2 = False
  15. ans += flag2
  16. print(ans)

D - Game in Momotetsu World

虽然正向搜索会很麻烦,但反过来从终点搜索起点使用DP记录即可

  1. using ll = long long;
  2. ll n, m, dp[2010][2010];
  3. char s[2011][2011];
  4. void solve() {
  5. scanf("%lld%lld", &n, &m);
  6. for (int i = 1; i <= n; i++)
  7. scanf("%s", s[i] + 1);
  8. memset(dp, 63, sizeof(dp));
  9. dp[n][m] = 0;
  10. for (int i = n; i > 0; i--)
  11. for (int j = m; j > 0; j--) {
  12. if (i == n && j == m)
  13. continue;
  14. dp[i][j] = max((s[i + 1][j] == '+' ? 1 : -1) - dp[i + 1][j],
  15. (s[i][j + 1] == '+' ? 1 : -1) - dp[i][j + 1]);
  16. }
  17. if (dp[1][1] > 0)cout << "Takahashi\n";
  18. else if (dp[1][1] == 0)cout << "Draw\n";
  19. else cout << "Aoki\n";
  20. }

E - Xor Distances

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define N 200005
  4. #define MOD 1000000007
  5. using namespace std;
  6. int n, d[N], ans;
  7. vector<int> to[N], w[N];
  8. void add(int u, int v, int wt) {to[u].push_back(v), w[u].push_back(wt);}
  9. void dfs(int u, int fa) {
  10. for (int i = 0, v; i < to[u].size(); i++)
  11. if ((v = to[u][i]) != fa)d[v] = d[u] ^ w[u][i], dfs(v, u);
  12. }
  13. signed main() {
  14. cin >> n;
  15. for (int i = 1, u, v, wt; i < n;
  16. i++)scanf("%lld%lld%lld", &u, &v, &wt), add(u, v, wt), add(v, u, wt);
  17. dfs(1, 0);
  18. for (int k = 0; k < 60; k++) {
  19. int a = 0;
  20. for (int i = 1; i <= n; i++)a += ((d[i] >> k) & 1);
  21. ans = (ans + a * (n - a) % MOD * ((1ll << k) % MOD) % MOD) % MOD;
  22. }
  23. cout << ans << endl;
  24. return 0;
  25. }

F - Insertion Sort

待补