补题链接:Here

Proble-A. Strange Table

根据 x 确定坐标确定的行数和列数。

  1. int main() {
  2. ios_base::sync_with_stdio(false), cin.tie(0);
  3. int _;
  4. for (cin >> _; _--;) {
  5. ll n, m, x;
  6. cin >> n >> m >> x;
  7. x--;
  8. ll col = x / n, row = x % n;
  9. cout << row * m + col + 1 << "\n";
  10. }
  11. return 0;
  12. }

Problem-B. Partial Replacement

题意:n组样例,每组单走一个字符串s,s由‘’和‘.’组成,可以把’‘号变成‘X’号,但是需要满足,首尾的‘.’号要变成‘X’号,相邻’X’距离不能超过k。求最终X个数最小值。

长度很小,直接暴搜,找到*号之后,下一个位置从x+k开始倒着找,找到最后直接返回,这样肯定是最小的了。

  1. int main() {
  2. ios_base::sync_with_stdio(false), cin.tie(0);
  3. int _;
  4. for (cin >> _; _--;) {
  5. int n, k;
  6. string s;
  7. cin >> n >> k >> s;
  8. int cnt = 1;
  9. int i = s.find_first_of('*');
  10. while (true) {
  11. int j = min(n - 1, i + k);
  12. for (; i < j and s[j] == '.'; --j)
  13. ;
  14. if (i == j) break;
  15. i = j, cnt++;
  16. }
  17. cout << cnt << "\n";
  18. }
  19. return 0;
  20. }

Problem-C. Double-ended Strings

两个字符串不大,可暴力

  1. int main() {
  2. ios_base::sync_with_stdio(false), cin.tie(0);
  3. int _;
  4. for (cin >> _; _--;) {
  5. string a, b;
  6. cin >> a >> b;
  7. int cnt = 0;
  8. int n = a.size(), m = b.size();
  9. for (int len = 1; len <= min(n, m); ++len) {
  10. for (int i = 0; i + len <= n; ++i)
  11. for (int j = 0; j + len <= m; ++j)
  12. if (a.substr(i, len) == b.substr(j, len))
  13. cnt = max(cnt, len);
  14. }
  15. cout << n + m - 2 * cnt << '\n';
  16. }
  17. return 0;
  18. }

Problem-D. Epic Transformation

这里要用一下优先队列去模拟消除的过程。

  1. int main() {
  2. ios_base::sync_with_stdio(false), cin.tie(0);
  3. int _;
  4. for (cin >> _; _--;) {
  5. int n, x;
  6. cin >> n;
  7. map<int, int> mp;
  8. priority_queue<pair<int, int>> q;
  9. for (int i = 0; i < n; ++i) {
  10. cin >> x;
  11. mp[x]++;
  12. }
  13. for (auto [x, y] : mp) q.push({y, x});
  14. int Size = n;
  15. while (q.size() >= 2) {
  16. auto [cnt1, x1] = q.top();
  17. q.pop();
  18. auto [cnt2, x2] = q.top();
  19. q.pop();
  20. cnt1--, cnt2--, Size -= 2;
  21. if (cnt1) q.push({cnt1, x1});
  22. if (cnt2) q.push({cnt2, x2});
  23. }
  24. cout << Size << "\n";
  25. }
  26. return 0;
  27. }

Problem-E. Restoring the Permutation

E题待补…