OvO http://codeforces.com/contest/909/problem/D

  CF 455 div2 D

  CF 909D

  算出模拟的复杂度之后就是一个很水的模拟题

  把字符串按照类似于行程编码的方式来表示,例如把 aaaabbccc 表示成 [4*a] [2*b] [3*c] 这样的形式([4*a] 这个用一个结构体表示)

  接下去就可以开心地敲模拟了,

  例如对于 [5*a] [4*b] [2*c] [4*b]  这样一个表,

  运行一次之后就变成了  [4*a] [2*b] [0*c] [3*b]

  然后进行压缩 变成 [4*a] [5*b]

  重点是复杂度的计算,每当你进行一次 O(1) 的操作(遍历数组,删除元素)时候,元素的总量(按 aabbc 是 个元素这样算)也会减1,所以总的复杂度是 O(n) 的,并不会超时

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm> using namespace std; const int M=1e6+44; struct Node
{
int val,num;
} q[M]; int lq;
char str[M]; void cps()
{
int k=lq;
lq=0;
for(int i=1;i<=k;i++)
if(q[i].num>0)
{
if(q[i].val==q[lq].val)
q[lq].num+=q[i].num;
else
q[++lq]=q[i];
}
} void solve()
{
int ans=0;
while(lq>1)
{
ans++;
for(int i=2;i<lq;i++)
q[i].num-=2;
q[1].num--,q[lq].num--;
cps();
}
printf("%d\n",ans);
} int main()
{
scanf("%s",str+1);
lq=strlen(str+1);
q[0].val=-1;
for(int i=1;i<=lq;i++)
q[i].val=str[i]-'a',q[i].num=1;
cps();
solve();
return 0;
}

  

Codeforces Round #455 (Div. 2) 909D. Colorful Points的更多相关文章

  1. Codeforces Round #455 (Div. 2)

    Codeforces Round #455 (Div. 2) A. Generate Login 题目描述:给出两个字符串,分别取字符串的某个前缀,使得两个前缀连起来的字符串的字典序在所有方案中最小, ...

  2. Codeforces Round #455 (Div. 2) D题(花了一个早自习补了昨晚的一道模拟QAQ)

    D. Colorful Points You are given a set of points on a straight line. Each point has a color assigned ...

  3. Codeforces Round #594 (Div. 2) A. Integer Points 水题

    A. Integer Points DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS to ...

  4. Codeforces Round #455 (Div. 2) 909E. Coprocessor

    题 OvO http://codeforces.com/contest/909/problem/E CF455 div2 E CF 909E 解 类似于拓扑排序地进行贪心, 对于 Ei=0 并且入度为 ...

  5. Codeforces Round #624 (Div. 3) F. Moving Points 题解

    第一次写博客 ,请多指教! 翻了翻前面的题解发现都是用树状数组来做,这里更新一个 线段树+离散化的做法: 其实这道题是没有必要用线段树的,树状数组就能够解决.但是个人感觉把线段树用熟了会比树状数组更有 ...

  6. Codeforces Round #230 (Div. 2) C Blocked Points

    题目链接 题意 : 给你一个半径为n的圆,圆里边还有圆上都有很多整点,让你找出与圆外的任意一个整点距离等于1的点. 思路 :这个题可以用枚举,画个图就发现了,比如说先数第一象限的,往下往右找,还可以找 ...

  7. Codeforces Round #418 (Div. 2).C two points

    C. An impassioned circulation of affection time limit per test 2 seconds memory limit per test 256 m ...

  8. Codeforces Round #455 (Div. 2) A. Generate Login【贪心】

    A. Generate Login time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  9. 【Codeforces Round #455 (Div. 2) A】Generate Login

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举两个串的前缀长度就好. 组出来. 排序. 取字典序最小的那个. [代码] #include <bits/stdc++.h& ...

随机推荐

  1. 【转】mysql分库分表,数据库分库分表思路

    原文:https://www.cnblogs.com/butterfly100/p/9034281.html 同类参考:[转]数据库的分库分表基本思想 数据库分库分表思路   一. 数据切分 关系型数 ...

  2. Feign 接口上传文件

    1)Encoder 配置注入容器 2) public class SpringFormEncoderExtension extends FormEncoder { /** * 使用默认的feign编码 ...

  3. mingw-w64 gcc std::thread 行为异常

    我用的 ming-w64 gcc 是通过 MSYS2 安装的,包名是 mingw-w64-x86_64-gcc,版本 9.2.0-2. 我发现 std::thread 行为异常. int main() ...

  4. 洛谷P2659 美丽的序列 单调栈模板

    P2659 美丽的序列 题目链接 https://www.luogu.org/problemnew/show/P2659 题目描述 为了研究这个序列的美丽程度,GD定义了一个序列的"美丽度& ...

  5. C程序设计语言练习 第三章

    3.3 else-if语句 折半查找,这里通过一个折半查找说明三路判定程序的用法.该函数用于判定已排序好的数组v中是否存在某个特定的值.数组v的元素必须以升序排列.如果v中包含x,则该函数返回x在v中 ...

  6. k-近邻(KNN) 算法预测签到位置

    分类算法-k近邻算法(KNN): 定义: 如果一个样本在特征空间中的k个最相似 (即特征空间中最邻近) 的样本中的大多数属于某一个类别,则该样本也属于这个类别 来源: KNN算法最早是由Cover和H ...

  7. COGS 2633. [HZOI 2016] 数列操作e

    [题目描述] 一个长度为n的序列,一开始序列数的权值都是0,有m次操作 支持两种操作, 1 L R x,给区间[L,R]内,第一个数加x,第二个数加2^2⋅x,第三个数加3^2⋅x...第R-L+1个 ...

  8. Python初学者常见错误详解

    Python初学者常见错误详解 0.忘记写冒号 在 if.elif.else.for.while.class.def 语句后面忘记添加 “:”   if spam == 42 print('Hello ...

  9. logstash grok

    input { file { path => "/opt/service/test-service/logs/catalina-error*.log" type => ...

  10. Date及DateFormat用法

    Date 与DateFormat之间的转化String <————>Date Date与Calendar 之间的转化Long<————>Date 日历小程序 Scanner i ...