题意略。

思路:

将字符分桶,然后暴力去扫,扫完合并。假设有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高并发系列 - 第17天:JUC中的循环栅栏CyclicBarrier常见的6种使用场景及代码示例

    这是java高并发系列第17篇. 本文主要内容: 介绍CyclicBarrier 6个示例介绍CyclicBarrier的使用 对比CyclicBarrier和CountDownLatch Cycli ...

  2. Envoy 源码分析--LDS

    Envoy 源码分析--LDS LDS 是 Envoy 用来自动获取 listener 的 API. Envoy 通过 API 可以增加.修改或删除 listener. 先来总结下 listener ...

  3. IDEA及IDEA汉化包

    IDEA 官网:http://www.jetbrains.com/idea/download/#section=windows IDEA社区版(百度云):http://pan.baidu.com/s/ ...

  4. C#命名规范(简述)

    命名空间,类,事件,接口,常量,属性,方法使用Pascal命名,即首字母大写  参数,变量(类字段)使用camel命名法,即首字母小写. Pascal 方式--所有单词第一个字母大写,其他字母小写.  ...

  5. 基础篇-1.2Java世界的规章制度(下)

    1 Java运算符 Java世界中的运算其实就是数学运算,而运算符就是其中的媒介. 算术运算符 操作符 描述 + 加法,对符号两边的数值相加 - 减法,符号左边的数减去右边的数 * 乘法,符号两边的数 ...

  6. ThinkPHP5.0 模板

    ThinkPHP5.0 模板 模板渲染 默认的视图目录是默认的模块下的view目录 渲染规则:调用 \think\View 类fetch方法 // [模板文件目录]/当前控制器名(小写+下划线)/当前 ...

  7. Heap Greedy

    1 239 Sliding Window Maximun 双端队列 public int[] maxSlidingWindow(int[] nums, int k) { if (nums == nul ...

  8. 前后端分离 之vue-cli 搭建项目mac 系统讲解

    前端项目搭建必备技术 webpack nodejs 搭建 vue-cli 的安装 以上技术自行了解安装 一:创建前端项目 采用vue-cli 脚手架 1:终端执行如下命令 vue init webpa ...

  9. RobotFramework_3.SeleniumLibrary操作(一)

    RobotFramework_3.SeleniumLibrary操作(一) *:first-child { margin-top: 0 !important; } body>*:last-chi ...

  10. 北大ACM试题分类+部分解题报告链接

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...