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. 【转帖】Linux的NUMA机制

    Linux的NUMA机制 http://www.litrin.net/2014/06/18/linux的numa机制/ NUMA(Non-Uniform Memory Access)字面直译为“非一致 ...

  2. [转帖]【Oracle】详解Oracle中NLS_LANG变量的使用

    [Oracle]详解Oracle中NLS_LANG变量的使用 https://www.cnblogs.com/HDK2016/p/6880560.html NLS_LANG=LANGUAGE_TERR ...

  3. 请给出一个Scala RDD的HelloWorld例子

    [学习笔记]package comimport org.apache.spark.rdd.RDDimport org.apache.spark.SparkConfimport org.apache.s ...

  4. (十四)springMvc 对 restful 的支持

    文章目录 restful 的概念 配置支持 restful 的前端控制器 配置不拦截静态资源 restful 的概念 restful 是一种开发理念: 对 url 进行规范 每个 url 代表一个资源 ...

  5. laravel_Supervisor队列

    Queue 1. 队列驱动 //数据库驱动,修改.env的QUEUE_DRIVER QUEUE_DRIVER=database 1. 数据库表 php artisan queue:table php ...

  6. 维护solr索引库

    一 2)solrcore    一个solr下可以有多个solrcore,每个solrcore就是一个独立的索引库3)solrconfig.xml    lib:配置solr的扩展包的位置,不指定路径 ...

  7. luogu2858奶牛零食题解--区间DP

    题目链接 https://www.luogu.org/problemnew/show/P2858 一句话题意: https://cn.vjudge.net/problem/POJ-3186#autho ...

  8. SparkSQL读取HBase数据

    这里的SparkSQL是指整合了Hive的spark-sql cli(关于SparkSQL和Hive的整合,见文章后面的参考阅读). 本质上就是通过Hive访问HBase表,具体就是通过hive-hb ...

  9. JS笛卡尔积算法与多重数组笛卡尔积实现方法示例

    js 笛卡尔积算法的实现代码,据对象或者数组生成笛卡尔积,并介绍了一个javascript多重数组笛卡尔积的例子,以及java实现笛卡尔积的算法与实例代码. 一.javascript笛卡尔积算法代码 ...

  10. weui 注意事项

    个人随笔日记,还请小心采纳为甚 手机移动web开发必须要做的两点: 1.body中加上ontouchstart,即<body ontouchstart>...</body>: ...