题解:

暴力,模拟。

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

#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的更多相关文章

  1. Codeforces Round #455 (Div. 2) 909D. Colorful Points

    题 OvO http://codeforces.com/contest/909/problem/D CF 455 div2 D CF 909D 解 算出模拟的复杂度之后就是一个很水的模拟题 把字符串按 ...

  2. Codeforces 909 D. Colorful Points (模拟)

    题目链接: Colorful Points 题意: 给出一段字符串(长度最大为1e6),每次操作可以删除字符串中所有相邻字符与其不同的字符.例如:aabcaa 删除一次就变成了aa,就无法再删除了.题 ...

  3. codeforces 19D D. Points 树套树

    D. Points Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/19/problem/D De ...

  4. codeforces B.Fixed Points

    link:http://codeforces.com/contest/347/problem/B 很简单,最多只能交换一次,也就是说,最多会增加两个.可能会增加一个.也可能一个也不增加(此时都是fix ...

  5. codeforces 577E E. Points on Plane(构造+分块)

    题目链接: E. Points on Plane time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  6. codeforces B. Fixed Points 解题报告

    题目链接:http://codeforces.com/problemset/problem/347/B 题目意思:给出一个包含n个数的排列a,在排列a中最多只能作一次交换,使得ai = i 这样的匹配 ...

  7. Codeforces909D Colorful Points(缩点)

    http://codeforces.com/problemset/problem/909/D 直接模拟超时.要运用缩点的方法,把相同的一段缩成一点,记录有几个. 对于非首尾的缩点每次-2,首尾的-1. ...

  8. Codeforces - 1081C - Colorful Bricks - 简单dp - 组合数学

    https://codeforces.com/problemset/problem/1081/C 这道题是不会的,我只会考虑 $k=0$ 和 $k=1$ 的情况. $k=0$ 就是全部同色, $k=1 ...

  9. codeforces 19 D. Points(线段树+set二分)

    题目链接:http://codeforces.com/contest/19/problem/D 题意:给出3种操作:1)添加点(x,y),2)删除点(x,y),3)查询离(x,y)最近的右上方的点. ...

随机推荐

  1. [LeetCode] Matrix 值修改系列,例题 Surrounded Regions,Set Matrix Zeroes

    引言 Matrix内部的值修改严格来讲放在一个系列里不大合适,因为对于不同的问题,所用的算法和技巧可能完全不同,权且这样归类,以后需要时再拆分吧. 例题 1 Given a 2D board cont ...

  2. vee-validate

    http://vee-validate.logaretm.com/ 表单校验,配合VUE使用

  3. MySQL主键和索引的联系及区别

    转载自:http://www.nowamagic.net/librarys/veda/detail/1954 关系数据库依赖于主键,它是数据库物理模式的基石.主键在物理层面上只有两个用途: 惟一地标识 ...

  4. laravel中form表单,ajax传值没反应

    laravel中form表单,ajax传值没反应时,可能是令牌有问题. form中添加: {{csrf_token()}} ajax中添加: data: {'page': page, '_token' ...

  5. python3之json模块使用

    1. json模块介绍 json是python自带的操作json的模块. python序列化为json时的数据类型转换关系: python格式 json格式 dict(复合类型) object lis ...

  6. ubuntu永久修改主机名

    1.查看主机名 在Ubuntu系统中,快速查看主机名有多种方法:其一,打开一个GNOME终端窗口,在命令提示符中可以看到主机名,主机名通常位于“@”符号后:其二,在终端窗口中输入命令:hostname ...

  7. spark作业提交参数设置(转)

    来源:https://www.cnblogs.com/arachis/p/spark_parameters.html 摘要 1.num-executors 2.executor-memory 3.ex ...

  8. xv6/sh.c

    // Shell. #include "types.h" #include "user.h" #include "fcntl.h" // P ...

  9. Term Term ssh登陆linux后 显示乱码

    setup----terminal----locale----“chinese” OK!!!!!

  10. Linux系统中提示/usr/bin/ld: cannot find -lxxx错误的通用解决方法

    在linux环境编译应用程式或lib的source code时常常会出现如下的错误讯息: 代码如下: /usr/bin/ld: cannot find -lxxx 这些讯息会随着编译不同类型的sour ...