题解:

暴力,模拟。

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

#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. Lucene 索引与检索架构图

  2. git入门篇shell

    什么是shell 在计算机科学中,Shell俗称壳,用来区别于Kernel(核),是指“提供使用者使用界面”的软件(命令解析器),它类似于windows系统下的cmd.exe, 它接收用户命令,然后调 ...

  3. Codeforces 221 B. Little Elephant and Numbers

    B. Little Elephant and Numbers time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  4. 2-sat基础题 BZOJ 1823

    http://www.lydsy.com/JudgeOnline/problem.php?id=1823 1823: [JSOI2010]满汉全席 Time Limit: 10 Sec  Memory ...

  5. ZOJ 3774 二次剩余

    LINK 题意:简单粗暴,求菲波那契数列每个数的m次的前n项和模1e9+7 思路:斐波那契通项式, 注意到有很多根号5,求二次剩余为5模1e9+7的解,显然我们可以直接找一个(383008016),然 ...

  6. JAVA多线程基础学习二:synchronized

    本篇主要介绍Java多线程中的同步,也就是如何在Java语言中写出线程安全的程序,如何在Java语言中解决非线程安全的相关问题,没错就是使用synchronized. 一.如何解决线程安全问题? 一般 ...

  7. React-music 全家桶项目

    React-Music 全家桶项目 一.简介 该项目是基于React全家桶开发的一个音乐播放器,技术栈采用:Webpack + React + React-redux + React-router + ...

  8. 【vijos】P1190 繁忙的都市

    [算法]最小生成树 #include<cstdio> #include<algorithm> using namespace std; ; ]; int fa[maxn],he ...

  9. 39、请用代码简答实现stack

    栈和队列是两种基本的数据结构,同为容器类型.两者根本的区别在于: stack:后进先出 queue:先进先出 PS:stack和queue是不能通过查询具体某一个位置的元素而进行操作的.但是他们的排列 ...

  10. spring-boot-JdbcTemplate

    添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...