题意略。

思路:

将字符分桶,然后暴力去扫,扫完合并。假设有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. WSASocket()创建套接字不成功解决方法

    这几天我在写一个模仿windows自带的ping程序,可是套接字总是创建不成功,在网上找了一些资料最后总算把问题解决了,现在总结一下. 解决方法:以管理员运行VS就行了我的是vs2013,vs2010 ...

  2. cachestat 安装文档

    安装环境:ubuntu18.04 安装步骤 1. 打开命令行,输入以下命令 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ...

  3. IO流总结1

    一.什么是流? 流就是字节序列的抽象概念,能被连续读取数据的数据源和能被连续写入数据的接收端就是流,流机制是Java及C++中的一个重要机制,通过流我们可以自由地控制文件.内存.IO设备等数据的流向. ...

  4. Hadoop自学系列集(一) ---- 使用VMware安装CentOS

     1.概述 笔者的学习环境--在VMware虚拟机下安装四个CentOS系统(搭建Hadoop集群用),其中一个为Master,三个为Slave,Master作为Hadoop集群中的NameNode, ...

  5. vim中 E212:无法打开并写入文件的解决办法

    很简单,就是用管理员身份打开这个文件 不要被网上的一些乱七八糟的迷惑了 sudo vim ....... 解决了问题请点个赞,谢谢

  6. Ping、Traceroute工作原理

    在工作开发过程中,我们经常会使用到ping和traceroute.在这里,我们将细述其工作原理,让你在会用的基础之上理解其内部工作过程. ICMP应用实例--Ping Ping 是 ICMP 的一个重 ...

  7. 前端笔记之React(六)ES6的Set和Map&immutable和Ramda和lodash&redux-thunk

    一.ES6的Set.Map数据结构 Map.Set都是ES6新的数据结构,都是新的内置构造函数,也就是说typeof的结果,多了两个: Set 是不能重复的数组 Map 是可以任何东西当做键的对象 E ...

  8. html+css+dom补充

    补充1:页面布局 一般像京东主页左侧右侧都留有空白,用margin:0 auto居中,一般.w. <!DOCTYPE html> <html lang="en"& ...

  9. Kibana对数据的可视化

    基于上一篇的操作,我们已经获得了数据,接下来我们就要处理数据,因此选用了Kibana 先来介绍一下, Kibana是一个针对Elasticsearch的开源分析及可视化平台,用来搜索.查看交互存储在E ...

  10. [Abp vNext 源码分析] - 7. 权限与验证

    一.简要说明 在上篇文章里面,我们在 ApplicationService 当中看到了权限检测代码,通过注入 IAuthorizationService 就可以实现权限检测.不过跳转到源码才发现,这个 ...