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. 【51nod】2589 快速讨伐

    51nod 2589 快速讨伐 又是一道倒着推改变世界的题... 从后往前考虑,设\(dp[i][j]\)表示还有\(i\)个1和\(j\)个\(2\)没有填,那么填一个1的话直接转移过来 \(dp[ ...

  2. c# dateTime格式转换为Unix时间戳工具类

    using System; using System.Collections.Generic; using System.Text; namespace TJCFinanceWriteOff.BizL ...

  3. hdu 1024 最大m段不相交线段和

    题目传送门//res tp hdu 数据范围1e6,若是开二维会爆 考虑用滚动数组优化 #include<iostream> #include<cstdio> #include ...

  4. springboot service dockerfile

    FROM java:8u111 MAINTAINER ianthony7@163.com # 定义变量 ENV WORK_DIR /opt ENV LOG_DIR /data/logs EXPOSE ...

  5. 搭建 python 3.5+pycharm 2017.1.3+django 1.12.0 首次 将sqlite3 迁移到mysql

  6. spark异常篇-OutOfMemory:GC overhead limit exceeded

    执行如下代码时报错 # encoding:utf-8 from pyspark import SparkConf, SparkContext from pyspark.sql import Spark ...

  7. MyBatis Java不同方式加载文件时的路径格式问题、Mybatis中加载.properties文件

    public class LoadPropTest { public static void main(String[] args) throws IOException { //一.Properti ...

  8. hdu 1068 最大子序列和变形,,,

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...

  9. request.getScheme() 使用方法(转)

    今天在看代码时,发现程序使用了 request.getScheme() .不明白是什么意思,查了一下.结果整理如下: 1.request.getScheme() 返回当前链接使用的协议:一般应用返回h ...

  10. Spring ——获取IOC容器时,构造方法、set方法、类方法执行顺序

    1,首先,我们在ApplicationContext.xml中会写下下面类的标示: <bean id="helloword" class="com.xt.frist ...