Codeforces Round #690 (Div. 3)

1462A. Favorite Sequence

简单看懂题即可,左边输出一个然后右边输出一个。

  1. void solve() {
  2. int n;
  3. cin >> n;
  4. vector<ll> a(n + 1);
  5. // ll a[n + 1]; //两种写法均可
  6. for (int i = 1; i <= n; ++i)
  7. cin >> a[i];
  8. int l = 1, r = n;
  9. bool f = true;
  10. for (int i = 1; i <= n; ++i) {
  11. if (f)
  12. cout << a[l++] << " ", f = false;
  13. else
  14. cout << a[r--] << " ", f = true;
  15. }
  16. cout << endl;
  17. }

1462B. Last Year’s Substring

一开始想错了,正确的思路是拆分字符串看是否能组成 2020

  1. void solve() {
  2. int n;
  3. string s;
  4. cin >> n >> s;
  5. bool f = false;
  6. for (int fir = 0; fir <= 4 && !f; fir++) {
  7. int sec = 4 - fir; //定位
  8. if (s.substr(0, fir) + s.substr(n - sec) == "2020")
  9. f = true;
  10. }
  11. cout << (f ? "YES\n" : "NO\n");
  12. }

1462C. Unique Number

😂打表。注意一下n > 45的话直接输出-1(因为0~9都被使用了最多到45)

  1. ll a[51] = {
  2. 0, 1, 2, 3, 4, 5, 6, 7,
  3. 8, 9, 19, 29, 39, 49, 59, 69,
  4. 79, 89, 189, 289, 389, 489, 589, 689,
  5. 789, 1789, 2789, 3789, 4789, 5789, 6789, 16789,
  6. 26789, 36789, 46789, 56789, 156789, 256789, 356789, 456789,
  7. 1456789, 2456789, 3456789, 13456789, 23456789, 123456789, -1, -1,
  8. -1, -1, -1,
  9. };
  10. void solve() {
  11. int n, cnt = 0;
  12. string s;
  13. cin >> n;
  14. cout << a[n] << endl;
  15. }

当然也可以正常分析:

  1. void solve() {
  2. int n;
  3. cin >> n;
  4. if (n > 45) {
  5. cout << -1 << endl;
  6. return;
  7. }
  8. string s;
  9. int nxt = 9;
  10. while (n > 0) {
  11. if (n >= nxt) {
  12. s += '0' + nxt;
  13. n -= nxt--;
  14. } else {
  15. s += '0' + n;
  16. break;
  17. }
  18. }
  19. reverse(s.begin(), s.end());
  20. cout << s << endl;
  21. }

D. Add to Neighbour and Remove

  1. void solve() {
  2. int n;
  3. cin >> n;
  4. vector<ll> a(n);
  5. for (int i = 0; i < n; ++i)
  6. cin >> a[i];
  7. ll ans = INT_MAX, sum = 0;
  8. for (int i = 0; i < n; ++i) {
  9. sum += a[i];
  10. ll cur = 0, toadd = 0;
  11. bool f = true;
  12. for (int j = 0; j < n; ++j) {
  13. if (cur)
  14. toadd++;
  15. cur += a[j];
  16. if (cur > sum) {
  17. f = false;
  18. break;
  19. } else if (cur == sum)
  20. cur = 0;
  21. }
  22. if (f && cur == 0) {
  23. // cout << toadd << " " << i << endl;
  24. ans = min(ans, toadd);
  25. }
  26. }
  27. cout << ans << endl;
  28. }

E1. Close Tuples (easy version)

  1. //unsolved