题意略。

思路:

将字符分桶,然后暴力去扫,扫完合并。假设有k个桶,每个桶里有n / k个数,那么我们应该要扫 n / (2 * k)次,每次的复杂度是k,最后算得复杂度是O(n)。

详见代码:

#include<bits/stdc++.h>
#define maxn 1000005
using namespace std; struct node{
int color;
int numb;
node(int a = ,int b = ){
color = a,numb = b;
}
}; node store[maxn];
int tail;
char str[maxn]; int main(){
scanf("%s",str);
store[tail++] = node(str[] - 'a',);
for(int i = ;str[i];++i){
if(store[tail - ].color == str[i] - 'a') store[tail - ].numb += ;
else store[tail++] = node(str[i] - 'a',);
}
int ans = ;
while(tail > ){
for(int i = ;i < tail;++i){
if(i == || i == tail - ) store[i].numb -= ;
else store[i].numb -= ;
}
++ans;
int temp = tail;
tail = ;
for(int i = ;i < temp;++i){
if(store[i].numb <= ) continue;
if(tail == || store[i].color != store[tail - ].color) store[tail++] = store[i];
else store[tail - ].numb += store[i].numb;
}
}
printf("%d\n",ans);
return ;
} /*
zaaaabcdaaaaz
*/

CodeForces 909D的更多相关文章

  1. CodeForces 909D Colorful Points

    题解: 暴力,模拟. 把字符串压缩一下,相同的处理成一位,记录下个数,然后暴力模拟即可. #include <bits/stdc++.h> using namespace std; con ...

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

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

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. Java 多线程部分面试题

    1..什么是线程,什么是进程,它们有什么区别和联系,一个进程里面是否必须有个线程 进程和线程的主要差别在于它们是不同的操作系统资源管理方式.进程有独立的地址空间,一个进程崩溃后,在保护模式下不会对其它 ...

  2. 开源分布式事务中间件Seata使用指南

    介绍 Seata 是阿里巴巴开源的分布式事务中间件,一种分布式事务解决方案,具有高性能和易于使用的微服务架构. 初衷 对业务无侵入:即减少技术架构上的微服务化所带来的分布式事务问题对业务的侵入 高性能 ...

  3. 头部姿态估计 - OpenCV/Dlib/Ceres

    基本思想 通过Dlib获得当前人脸的特征点,然后通过旋转平移标准模型的特征点进行拟合,计算标准模型求得的特征点与Dlib获得的特征点之间的差,使用Ceres不断迭代优化,最终得到最佳的旋转和平移参数. ...

  4. firewalld防火墙命令规则设置

    1.firewalld的基本使用 启动/关闭: systemctl start/stop firewalld 查看状态: systemctl status firewalld 开机启用/禁用 : sy ...

  5. 动态开内存(malloc与calloc)

    malloc与calloc 1.函数原型 #include<stdlib.h> void *malloc(unsigned int size);     //申请size字节的内存 voi ...

  6. html的一些基本语法学习与实战

    其实在学校前端开始之前,问过自己为什么要学,因为自己学的比较杂,直到现在刚刚毕业出来工作了,才明确了方向了,要往嵌入式方向走,但是随着时代的发展,在编程和智能硬件结合的越来越紧密,特别是物联网这一块, ...

  7. spring-boot-plus1.2.0-RELEASE发布-快速打包-极速部署-在线演示

    spring-boot-plus 一套集成spring boot常用开发组件的后台快速开发脚手架 Purpose 每个人都可以独立.快速.高效地开发项目! Everyone can develop p ...

  8. Java连载11-转义字符&整数型

    一.转义符 1.\'代表单引号:\\代表\; 二.native2ascii.exe JDK中自带的native2ascii.exe命令,可以将文字转换成unicode编码形式 我们使用这个程序尝试一下 ...

  9. java并发编程(十二)----(JUC原子类)数组类型介绍

    上一节我们介绍过三个基本类型的原子类,这次我们来看一下数组类型: AtomicIntegerArray, AtomicLongArray, AtomicReferenceArray.其中前两个的使用方 ...

  10. 动态SQL查询

    if+where: 用于查询操作,where标签可以智能判断是否添加and.or.where关键词 示例: <select id="findByParam" resultTy ...