51鸽了几天,有几场比赛的题解还没发布,今天晚上会补上的

1520A. Do Not Be Distracted!

问题分析

模拟,如果存在已经出现的连续字母段则输出NO

  1. using ll = long long;
  2. void solve() {
  3. int n;
  4. string s;
  5. cin n s;
  6. bool vis[30] = {false};
  7. for (int i = 0; i n; ++i) {
  8. if (vis[s[i] - 'A']) {
  9. cout NOn;
  10. return;
  11. }
  12. int j = i;
  13. while (s[j] == s[i]) j++;
  14. vis[s[i] - 'A'] = true;
  15. i = j;
  16. }
  17. cout YESn;
  18. }

1520B. Ordinary Numbers

  1. using ll = long long;
  2. bool check(int x) {
  3. string temp = to_string(x);
  4. for (int i = 0; i temp.size() - 1; i++)
  5. if (temp[i] != temp[i + 1]) return false;
  6. return true;
  7. }
  8. ll ans;
  9. void solve() {
  10. ll n;
  11. cin n, ans = 0;
  12. int k = 1, temp = 1;
  13. for (int i = temp; i = n; i += temp) {
  14. if (check(i)) ans++;
  15. else {
  16. temp = temp 10 + 1;
  17. i = 0;
  18. }
  19. }
  20. cout ans endl;
  21. }

1520C. Not Adjacent Matrix

问题分析:构造思想

Codeforces Round #719 (Div. 3) A~E题解 - 图1 ,无论怎么构造矩阵都会产生相邻的矩阵。
其他情况,以 Codeforces Round #719 (Div. 3) A~E题解 - 图2 为起点每次间隔 + 2,因为 数值不超过 Codeforces Round #719 (Div. 3) A~E题解 - 图3 所以,在大于此值时再从 Codeforces Round #719 (Div. 3) A~E题解 - 图4 开始枚举,这样一定能填充整个 Codeforces Round #719 (Div. 3) A~E题解 - 图5 矩阵

  1. void solve() {
  2. int n;
  3. cin n;
  4. vectorint a(100 100 + 10);
  5. if (n == 2) {
  6. cout -1 n;
  7. return;
  8. }
  9. int cnt = 1;
  10. for (int i = 1; i = n n; ++i) {
  11. if (cnt = n n) a[i] = cnt, cnt += 2;
  12. if (cnt n n) cnt = 2;
  13. }
  14. for (int i = 1; i = n n; ++i) {
  15. cout a[i];
  16. if (i % n == 0) cout n;
  17. else
  18. cout ;
  19. }
  20. }

1520D. Same Differences

问题分析

变换公式,Codeforces Round #719 (Div. 3) A~E题解 - 图6

所以我们可以存储 Codeforces Round #719 (Div. 3) A~E题解 - 图7 的值,然后进行组合数计算 Codeforces Round #719 (Div. 3) A~E题解 - 图8Codeforces Round #719 (Div. 3) A~E题解 - 图9 代表 Codeforces Round #719 (Div. 3) A~E题解 - 图10 的个数

  1. using ll = long long;
  2. void solve() {
  3. int n;
  4. mapint, ll mp;
  5. cin n;
  6. for (ll i = 1, x; i = n; ++i) {
  7. cin x;
  8. mp[x - i]++;
  9. }
  10. ll cnt = 0;
  11. for (auto p mp) cnt += p.second (p.second - 1) 2;
  12. cout cnt n;
  13. }

1520E. Arranging The Sheep

问题分析:贪心

对于绵羊序列,两端都往中间移动一定最优

  1. void solve() {
  2. int n;
  3. string s;
  4. cin n s;
  5. vectorint a;
  6. int empty = 0;
  7. for (int i = 0; i n; ++i) {
  8. if (s[i] == '.') empty++;
  9. else
  10. a.push_back(empty);
  11. }
  12. int mid = (a.size() - 1) 1;
  13. ll ans = 0;
  14. for (auto x a) ans += abs(x - a[mid]);
  15. cout ans n;
  16. }

1520F1. Guess the K-th Zero (Easy version)

  1. 待补