补题链接:Here

经典手速场

1509A. Average Height

题意:要找出最大不平衡对序列

先输出奇数,然后输出偶数

  1. void solve() {
  2. int n;
  3. cin >> n;
  4. vector<int> odd, even;
  5. for (int i = 0, x; i < n; ++i) {
  6. cin >> x;
  7. if (x & 1) odd.push_back(x);
  8. else
  9. even.push_back(x);
  10. }
  11. for (int x : odd) cout << x << " ";
  12. for (int x : even) cout << x << " ";
  13. cout << "\n";
  14. }

1509B. TMT Document

题意:给定一个 T-M字符串,求问是否能全拆分为 TMT 子序列

思路:

要能组成 TMT 就要是 T、M顺序一定并 cntT = 2 * cntMCodeforces Round #715 (Div. 2) (A~D 补题记录) - 图1

  1. void solve() {
  2. int n;
  3. string s;
  4. cin >> n >> s;
  5. int ct = 0, cm = 0;
  6. bool f = true;
  7. for (int i = 0; f && i < n; ++i) {
  8. s[i] == 'T' ? ct++ : cm++;
  9. if (cm > ct || (ct > 2 * cm + n / 3 - cm)) f = false;
  10. }
  11. cout << (f && cm * 2 == ct && n % 3 == 0 ? "YES\n" : "NO\n");
  12. }

1509C. The Sports Festival

题意:

学生会要参加接力赛,每位成员跑步速度为 Codeforces Round #715 (Div. 2) (A~D 补题记录) - 图2 ,给定定义:

Codeforces Round #715 (Div. 2) (A~D 补题记录) - 图3%20-%20min(a_1%2Ca_2%2C%5Cdots%2Ca_i)%0A#card=math&code=d_i%20%3D%20max%28a_1%2Ca_2%2C%5Cdots%2Ca_i%29%20-%20min%28a_1%2Ca_2%2C%5Cdots%2Ca_i%29%0A)

求出最小的 Codeforces Round #715 (Div. 2) (A~D 补题记录) - 图4

思路:

待补。

  1. using ll = long long;
  2. ll dp[2005][2005];
  3. int n;
  4. int A[2005];
  5. void solve() {
  6. cin >> n;
  7. for (int i = 1; i <= n; ++i) cin >> A[i];
  8. sort(A + 1, A + n + 1);
  9. for (int i = 1; i <= n; ++i)
  10. for (int j = i + 1; j <= n; ++j) dp[i][j] = 1e18;
  11. for (int i = 1; i <= n; ++i) dp[i][i] = 0;
  12. for (int len = 1; len < n; ++len) {
  13. for (int i = 1; i + len - 1 <= n; ++i) {
  14. int j = i + len - 1;
  15. if (j < n) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + A[j + 1] - A[i]);
  16. if (i > 1) dp[i - 1][j] = min(dp[i - 1][j], dp[i][j] + A[j] - A[i - 1]);
  17. }
  18. }
  19. cout << dp[1][n] << '\n';
  20. }

另外一种写法

  1. using ll = long long;
  2. void solve() {
  3. int n;
  4. cin >> n;
  5. vector<ll> s(n);
  6. for (ll &x : s) cin >> x;
  7. sort(s.begin(), s.end());
  8. vector<ll> dp0(n), dp1(n);
  9. for (int k = 1; k < n; ++k) {
  10. for (int i = k; i < n; ++i)
  11. dp1[i] = min(dp0[i - 1], dp0[i]) + s[i] - s[i - k];
  12. swap(dp0, dp1);
  13. }
  14. cout << dp0[n - 1] << '\n';
  15. }

1508A/1509D. Binary Literature

题意:

在一场二进制小说写作比赛中,需要由三个长度为 Codeforces Round #715 (Div. 2) (A~D 补题记录) - 图5 的字符串组成的 Codeforces Round #715 (Div. 2) (A~D 补题记录) - 图6 长度的字符串(其中至少包括 Codeforces Round #715 (Div. 2) (A~D 补题记录) - 图7 个字符串的两个作为子序列)

先贴一下AC代码

  1. void solve() {
  2. int n;
  3. string a, b, c;
  4. cin >> n >> a >> b >> c;
  5. int x = 0, y = 0, z = 0;
  6. for (int i = 0; i < 2 * n; ++i) {
  7. if (a[i] == '1') ++x;
  8. if (b[i] == '1') ++y;
  9. if (c[i] == '1') ++z;
  10. }
  11. if (x > y) swap(a, b), swap(x, y);
  12. if (y > z) swap(b, c), swap(y, z);
  13. if (x > y) swap(a, b), swap(x, y);
  14. char cc = '0';
  15. if (y > n) {
  16. cc = '1';
  17. swap(a, c), swap(x, z);
  18. }
  19. x = y = 0;
  20. string ans = "";
  21. while (true) {
  22. while (x < 2 * n && a[x] != cc) ans += a[x], ++x;
  23. while (y < 2 * n && b[y] != cc) ans += b[y], ++y;
  24. if (x == 2 * n && y == 2 * n) break;
  25. ans += cc;
  26. if (x < 2 * n) x++;
  27. if (y < 2 * n) y++;
  28. }
  29. while (ans.size() < 3 * n) ans += '0';
  30. cout << ans << '\n';
  31. }