比赛链接:Here

A题挺水的就不写了

1304B - Longest Palindrome

题意:

  • 输入 Codeforces Round #620 (Div. 2) - 图1 个长度为 Codeforces Round #620 (Div. 2) - 图2 的字符串,问这些字符串能组成的最长回文串有多长。

思路:

  1. 贪心的思想,我们只需要用当前字符串以及寻找该字符串的反向串是否存在,如果存在的话,就把该字符串与它的反向串添加进答案串的首尾。
  2. 注意中间的那个字符串,如果我们输入的字符串中有回文串,且该串的反向串也不存在的话,可以把该串单独放在答案串的中间。
  1. string s[110];
  2. map<string, int>mp;
  3. bool check(string s) {
  4. int n = s.size();
  5. for (int i = 0, j = n - 1; i <= n / 2; ++i, j--)
  6. if (s[i] != s[j]) return 0;
  7. return 1;
  8. }
  9. int main() {
  10. cin.tie(nullptr)->sync_with_stdio(false);
  11. int n, m; cin >> n >> m;
  12. for (int i = 0; i < n; ++i) cin >> s[i], mp[s[i]] = 1;
  13. string ans, z, t;
  14. bool f = 0;
  15. for (int i = 0; i < n; ++i) {
  16. if (check(s[i])) z = s[i], f = 1;
  17. else {
  18. reverse(s[i].begin(), s[i].end());
  19. string tmp = s[i];
  20. reverse(s[i].begin(), s[i].end());
  21. if (mp[tmp] == 1) {
  22. t += tmp;
  23. mp[tmp] = 0;
  24. }
  25. }
  26. mp[s[i]] = 0;
  27. }
  28. ans += t;
  29. reverse(t.begin(), t.end());
  30. if (f) ans += z;
  31. ans += t;
  32. cout << int(ans.size()) << "\n";
  33. if (int(ans.size()))cout << ans << "\n";
  34. }

1304C - Air Conditioner

题意:

  • 输入 Codeforces Round #620 (Div. 2) - 图3,再输入 Codeforces Round #620 (Div. 2) - 图4 个顾客的信息,分别为客人来的时间,客人需要的温度范围,每分钟可以进行一次三种操作之一:升温,降温和不变。问能否满足所有客人的需求。

思路:

一开始写复杂了,这道题本质就是暴力模拟,要满足所有客人的需求,那么就用当前客人与下一个客人的时间差来取温度的最大(r)和最小值(l),当下一个客人来时再判断这个客人的需求是否在这个[l,r]之内。

  1. int main() {
  2. cin.tie(nullptr)->sync_with_stdio(false);
  3. int _; for (cin >> _; _--;) {
  4. ll n, m;
  5. cin >> n >> m;
  6. ll t = 0, l = m, r = m;
  7. bool f = 1;
  8. while (n--) {
  9. ll ti, x, y;
  10. cin >> ti >> x >> y;
  11. l = l - (ti - t), r = r + (ti - t);
  12. t = ti;
  13. l = max(l, x), r = min(r, y);
  14. if (l > r) f = 0;
  15. }
  16. cout << (f ? "YES\n" : "NO\n");
  17. }
  18. }

1304D - Shortest and Longest LIS

题意:

  • 给定一个 Codeforces Round #620 (Div. 2) - 图5 ,与构造规则,要求构造出符合构造规则的LIS最小和最大的串

思路:

原本想试试DP,写状态转移发现最短序列的话,对于一串大于号,我们把当前未使用过的比较大的数尽可能的放在左边。最长序列就是反过来,尽可能的放未使用过的小的数放在左边即可

简单来说就是贪心

  1. const int N = 2e5 + 10;
  2. ll a[N];
  3. int main() {
  4. cin.tie(nullptr)->sync_with_stdio(false);
  5. int _; for (cin >> _; _--;) {
  6. int n; string s;
  7. cin >> n >> s;
  8. int nn = n, lst = 0;
  9. for (int i = 0; i < n; ++i) {
  10. if (s[i] == '>' || i == n - 1) {
  11. for (int j = i; j >= lst; j--)a[j] = nn--;
  12. lst = i + 1;
  13. }
  14. }
  15. for (int i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1];
  16. nn = 1, lst = 0;
  17. for (int i = 0; i < n; ++i) {
  18. if (s[i] == '<' || i == n - 1) {
  19. for (int j = i; j >= lst; j--) a[j] = nn++;
  20. lst = i + 1;
  21. }
  22. }
  23. for (int i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1];
  24. }
  25. }

E,F不会做….明明挺多人都过了QAQ