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. javaweb配置连接mysql数据库

    1.首先新建基础连接类BaseDao,在这里配置链接的数据库名称,用户名以及密码,以及执行读与写操作的父方法,代码如下: package com.demo.dao; import java.sql.D ...

  2. 剑指offer47:位运算+递归。求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。

    1 题目描述 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 2 思路和方法 (1)递归,不能使用if等 ...

  3. lg 1478

    好多天没碰代码了,感觉忘得差不多了,没有学习感觉罪恶深重,从今天起开始补题啊啊! 简单零一背包,套模板就行. #include<bits/stdc++.h> using namespace ...

  4. Python【条件判断】

    单向判断ifif xxx: #冒号 #条件 print(xxx) #缩进是四个空格或一个Tab键#被缩进的内容(print()函数)和if条件语句组成了一个代码块(一个整体)————————————— ...

  5. Python 第一节随堂练习

    作业: 1 从键盘输入一个整数,判断该数字能否被2和3同时整除,能否被2整除,能否被3整除,不能被2和3整除,输出相应信息 1 my_num = int(input('请输入一个整数')) 2 if ...

  6. selenium登录4399

    from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from seleni ...

  7. Django-djangorestframework-渲染模块

    目录 渲染模块 渲染模块的效果 源码分析 如何自定义配置使用渲染类 自定义渲染模块 渲染模块 可以根据用户请求 URL 或 用户可接受的类型,筛选出合适的 渲染组件. reponse 数据 json ...

  8. spring-cloud 学习三 服务提供者

    基于spring-boot创建一个module提供服务 使用mysql数据库,dao使用mybatis,数据库连接池使用阿里的druid 添加maven依赖 <parent> <gr ...

  9. Unity 用脚本给EventTrigger添加各种事件

    using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Eve ...

  10. c# redis密码验证笔记

    参考博客https://www.cnblogs.com/qukaicheng/p/7514168.html写的 安装教程https://www.redis.net.cn/tutorial/3503.h ...