A - Rotate

先输出第二和第三个字符,然后再输出第一个字符即可

B - Visibility

AtCoder Beginner Contest 197(Sponsored by Panasonic) Person Editorial - 图1#card=math&code=%28x%2Cy%29) 作为起点向4个方向探索不是 # 的点,注意一下会在AtCoder Beginner Contest 197(Sponsored by Panasonic) Person Editorial - 图2#card=math&code=%28x%2Cy%29)重复计算 AtCoder Beginner Contest 197(Sponsored by Panasonic) Person Editorial - 图3 次,所以要 cnt - 3

  1. int main() {
  2. ios_base::sync_with_stdio(false), cin.tie(0);
  3. int H, W, X, Y;
  4. cin >> H >> W >> X >> Y;
  5. X -= 1, Y -= 1;
  6. vector<string> s(H);
  7. for (int i = 0; i < H; ++i) cin >> s[i];
  8. int cnt = 0;
  9. // 向 4 个方向探索
  10. for (int i = X; i < H and s[i][Y] != '#'; ++i) cnt++;
  11. for (int i = X; i >= 0 and s[i][Y] != '#'; --i) cnt++;
  12. for (int i = Y; i < W and s[X][i] != '#'; ++i) cnt++;
  13. for (int i = Y; i >= 0 and s[X][i] != '#'; --i) cnt++;
  14. cout << cnt - 3 << "\n";
  15. return 0;
  16. }

C - ORXOR Editorial

Good,位运算典型题

  1. int main() {
  2. ios_base::sync_with_stdio(false), cin.tie(0);
  3. int n;
  4. cin >> n;
  5. vector<int> a(n);
  6. for (int& x : a) cin >> x;
  7. int ans = INT_MAX;
  8. for (int i = 0; i < (1 << (n - 1)); ++i) {
  9. int xored = 0, ored = 0;
  10. for (int j = 0; j <= n; ++j) {
  11. if (j < n) ored |= a[j];
  12. if (j == n || (i >> j & 1)) xored ^= ored, ored = 0;
  13. }
  14. ans = min(ans, xored);
  15. }
  16. cout << ans << "\n";
  17. return 0;
  18. }

D - Opposite

  1. // C++似乎内置了 PI 也可以不定义 M_PI
  2. #define M_PI 3.14159265358979323846
  3. int main() {
  4. ios_base::sync_with_stdio(false), cin.tie(0);
  5. int N;
  6. double xx, yy, x, y;
  7. cin >> N >> xx >> yy >> x >> y;
  8. double a = (xx + x) / 2, b = (yy + y) / 2;
  9. xx -= a, yy -= b;
  10. double m = xx * cos(2 * M_PI / N) - yy * sin(2 * M_PI / N);
  11. double n = xx * sin(2 * M_PI / N) + yy * cos(2 * M_PI / N);
  12. cout << fixed << setprecision(12) << m + a << "\n" << n + b;
  13. return 0;
  14. }

E - Traveler

很好的处理方法

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. const int N = 2e5 + 7;
  5. vector<int> v[N];
  6. ll l[N], r[N];
  7. int main() {
  8. ios_base::sync_with_stdio(false), cin.tie(0);
  9. int n;
  10. cin >> n;
  11. for (int i = 0, x, c; i < n; ++i) {
  12. cin >> x >> c;
  13. v[c].push_back(x);
  14. }
  15. v[0].push_back(0);
  16. v[n + 1].push_back(0);
  17. // int ans = 0;
  18. for (int i = 1, j = 0; i <= n + 1; ++i) {
  19. if (v[i].empty()) continue;
  20. sort(v[i].begin(), v[i].end());
  21. int lx = v[i].front(), rx = v[i].back();
  22. int ly = v[j].front(), ry = v[j].back();
  23. // cout << lx << " " << rx << "\n";
  24. l[i] = min(abs(rx - ly) + l[j], abs(rx - ry) + r[j]) + rx - lx;
  25. r[i] = min(abs(lx - ly) + l[j], abs(lx - ry) + r[j]) + rx - lx;
  26. // ans = min(l[i], r[i]);
  27. j = i;
  28. }
  29. cout << min(l[n + 1], r[n + 1]) << "\n";
  30. return 0;
  31. }

F - Construct a Palindrome

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1002;
  4. int n, m;
  5. char s[2];
  6. struct node {
  7. int s, t, sp;
  8. } r;
  9. queue<node> q;
  10. vector<int> a[N][26];
  11. int ans = 1e9, vis[N][N];
  12. //把边看成点
  13. //对于两对边(a,b) (c,d)
  14. //如果(a,c) 和 (b,c)之间存在边 而且边上的字母相同的话
  15. //那么这两个边变成的点就可以联通
  16. int bfs() {
  17. while (!q.empty()) {
  18. r = q.front();
  19. q.pop();
  20. if (r.sp == ans) return ans << 1;
  21. for (int i = 0; i < 26; ++i)
  22. for (int j = 0; j < a[r.s][i].size(); ++j)
  23. for (int k = 0; k < a[r.t][i].size(); ++k) {
  24. int ns = a[r.s][i][j];
  25. int nt = a[r.t][i][k];
  26. if (ns == r.t || nt == r.s) return r.sp << 1 | 1;
  27. if (ns == nt) ans = r.sp + 1;
  28. if (vis[ns][nt]) continue;
  29. vis[ns][nt] = 1;
  30. q.push((node){ns, nt, r.sp + 1});
  31. }
  32. }
  33. return -1;
  34. }
  35. int main() {
  36. scanf("%d%d", &n, &m);
  37. for (int x, y; m; --m) {
  38. scanf("%d%d%s", &x, &y, s);
  39. a[x][*s - 'a'].push_back(y);
  40. a[y][*s - 'a'].push_back(x);
  41. }
  42. vis[1][n] = 1;
  43. q.push((node){1, n, 0});
  44. printf("%d", bfs());
  45. }