baidu

发布时间 2023-04-21 22:17:14作者: 浅渊

冰雪大冒险

#include <bits/stdc++.h>

#define KV(x) #x << " " << x

signed main() {
  std::cin.tie(nullptr)->sync_with_stdio(false);

  int n, m;
  std::cin >> n >> m;
  int sx, sy;
  std::cin >> sx >> sy;
  int k;
  std::cin >> k;
  std::vector<std::vector<int>> a(n + 1, std::vector<int>(m + 1));
  for (int i = 0; i < k; i++) {
    int x, y;
    std::cin >> x >> y;
    a[x][y] = 1;
  }

  std::string s;
  std::cin >> s;

  auto trans = [&](char ch) -> std::array<int, 2> {
    if (ch == 'D') return std::array<int, 2>{1, 0};
    else if (ch == 'L') return std::array<int, 2>{0, -1};
    else if (ch == 'R') return std::array<int, 2>{0, 1};
    else return std::array<int, 2>{-1, 0};
  };

  for (int i = 0; i < static_cast<int>(s.size()); i++) {
    std::array<int, 2> now = trans(s[i]);
    int xx = sx + now[0], yy = sy + now[1];
    while(xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[xx][yy] == 0) {
      sx = xx, sy = yy;
      // std::cerr << KV(sx) << " " << KV(sy) << "\n";
      xx += now[0], yy += now[1];
    }
  }

  std::cout << sx << " " << sy << "\n";
}

房间打扫

#include <bits/stdc++.h>

#define KV(x) #x << " " << x

signed main() {
  std::cin.tie(nullptr)->sync_with_stdio(false);

  int Max = 0;
  std::map<std::string, int> cnt;
  int n;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::string s;
    std::cin >> s;
    cnt[s]++;
    Max = std::max(cnt[s], Max);
  }

  std::cout << Max << "\n";
}

数字统计

#include <bits/stdc++.h>

#define KV(x) #x << " " << x

signed main() {
  std::cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  std::cin >> n;

  int ans = 0;

  auto trans = [&](int x) -> bool {
    std::string now = std::to_string(x);
    std::reverse(now.begin(), now.end());
    int y = stoi(now);
    return x % y == 0;
  };

  for (int i = 1; i <= n; i++) {
    ans += trans(i);
  }
  std::cout << ans << "\n";
}

函数的幂

#include <bits/stdc++.h>

#define KV(x) #x << " " << x

signed main() {
  std::cin.tie(nullptr)->sync_with_stdio(false);
  int a, b, C, D;
  std::cin >> a >> b >> C >> D;
  int ans = 0;
  std::function<int(int, int)> f = [&](int x, int y) -> int {
    if (x == 1) return (1ll * C * y % 10 + D % 10) % 10;
    else {
      return f(x - 1, f(x - 1, y));
    }
  };

  std::cout << f(a, b) << "\n";
}

项链

#include <bits/stdc++.h>

#define KV(x) #x << " " << x

signed main() {
  std::cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (auto& x : a) std::cin >> x;
  std::sort(a.begin(), a.end());
  long long ans = 0;
  for (int i = n - 1; i >= (n + 1) / 2; i--) ans += a[i];
  for (int i = 0; i < n / 2; i++) ans -= a[i];
  ans <<= 1;
  std::cout << ans << "\n";
}

污渍

#include <bits/stdc++.h>

#define KV(x) #x << " " << x
#define int long long
signed main() {
  std::cin.tie(nullptr)->sync_with_stdio(false);
  std::vector<std::array<int, 3>> p(2);
  long long ans = 0;
  for (int i = 0; i < 2; i++) {
    std::cin >> p[i][0] >> p[i][1] >> p[i][2];
    ans += 1ll * p[i][2] * p[i][2];
  }

  std::pair<int, int> A = std::make_pair(std::min(std::max(p[0][0], p[1][0]), std::min(p[0][0] + p[0][2], p[1][0] + p[1][2])), 
                                         std::max(std::min(p[0][1], p[1][1]), std::max(p[0][1] - p[0][2], p[1][1] - p[1][2])));
  std::pair<int, int> B = std::make_pair(std::min(p[1][0] + p[1][2], p[0][0] + p[0][2]), 
                                         std::max(p[1][1] - p[1][2], p[0][1] - p[0][2]));
  // std::cout << A.first << " " << A.second << "\n";
  // std::cout << B.first << " " << B.second << "\n";
  if (B.first >= A.first && B.second <= A.second)
    ans -= std::max(0ll, 1ll * (B.first - A.first) * (A.second - B.second));
  std::cout << ans << "\n";
}

剧场

#include <bits/stdc++.h>

signed main() {
  int n;
  std::cin >> n;
  std::vector<std::vector<char>> g(n + 10, std::vector<char>(n + 10, '0'));
  int N = n * n;
  for (int tc = 0; tc < N; tc++) {
    for (int i = n; i; i--) {
      for (int j = n; j; j--) {
        if (j == 1) {
          if (g[i][j] == '0' && g[i - 1][n] == '1') {
            g[i][j] = '1';
            g[i - 1][n] = '0';
          }
        } else {
          if (g[i][j] == '0' && g[i][j - 1] == '1') {
            g[i][j] = '1';
            g[i][j - 1] = '0';
          }
        }
      }
    }
    char ch;
    std::cin >> ch;
    if (ch & 1)
      g[1][1] = '1';
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int ok = 0;
      for (int j = 1; j <= n; j++) {
        if (g[i][j] == '1')
          ok |= 1;
      }
      ans += ok;
    }
    std::cout << ans << " \n"[tc == N - 1];
  }
}