CodeForces 909D Colorful Points

Posted Fighting Heart

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces 909D Colorful Points相关的知识,希望对你有一定的参考价值。

题解:

暴力,模拟。

把字符串压缩一下,相同的处理成一位,记录下个数,然后暴力模拟即可。

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e6 + 10;
char s[maxn];

struct X {
  char id;
  int num;
}p[maxn], q[maxn];
int sz;

void work() {
  for(int i = 0; i <= sz; i ++) {
    if(i == 0 || i == sz) {
      p[i].num --;
    } else {
      p[i].num --;
      p[i].num --;
    }
  }
  int cnt = 0;
  for(int i = 0; i <= sz; i ++) {
    if(p[i].num <= 0) continue;
    q[cnt ++] = p[i];
  }
  sz = 0;
  p[0] = q[0];
  for(int i = 1; i < cnt; i ++) {
    if(q[i].id == p[sz].id) p[sz].num += q[i].num;
    else {
      sz ++;
      p[sz] = q[i];
    }
  }
}

int main() {
  scanf("%s", s);
  p[sz].id = s[0];
  p[sz].num = 1;
  for(int i = 1; s[i]; i ++) {
    if(s[i] == p[sz].id) p[sz].num ++;
    else  {
      sz ++;
      p[sz].id = s[i];
      p[sz].num = 1;
    }
  }
  int ans = 0;
  while(1) {
    if(sz == 0) break;
    work();
    ans ++;
  }
  printf("%d\\n", ans);
  return 0;
}

 

以上是关于CodeForces 909D Colorful Points的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 909 D. Colorful Points (模拟)

Codeforces Round #635 (Div. 2) D-Xenia and Colorful Gems 二分

Codeforces Round #635 (Div. 2) DXenia and Colorful Gems

Codeforces Round #286 (Div. 1) D. Mr. Kitayuta's Colorful Graph

Avito Cool Challenge 2018 C. Colorful Bricks 排列组合

Avito Cool Challenge 2018:C. Colorful Bricks