题目链接: Colorful Points

题意:

  给出一段字符串(长度最大为1e6),每次操作可以删除字符串中所有相邻字符与其不同的字符。例如:aabcaa 删除一次就变成了aa,就无法再删除了。题目要求所给出的字符串要操作几次后才无法操作。

题解:

  可以把整个字符串化简为相邻字符都不同的串,把每个位置字符的个数记录下来,比如aaaabbbbccccdddd -> [4*a][4*b][4*c][4*d]。然后暴力求。@。@这题比我想象中的也暴力太多了,妈耶,刷新了我对D题的认知。

 #include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6+;
const int MOD = 1e9+;
char vec[MAX_N];
int res[MAX_N];
char tran[MAX_N];
int main()
{
int N,M,T;
while(~scanf("%s",vec))
{
memset(res,,sizeof(res));
int len = strlen(vec);
int pos = ;
res[] = ;
char pre = vec[];
tran[pos] = pre;
for(int i=;i<len;i++)
{
if(vec[i] == pre) res[pos] ++;
else
{
res[++pos] = ;
pre = vec[i];
tran[pos] = pre;
}
} int num = pos + ;
int ans = ;
while(num > )
{
res[] -= ;
res[num-] -= ;
for(int i=;i<num-;i++)
{
res[i] -= ;
}
int t = ;
for(int i=;i<num;i++)
{
if(res[i]>)
{
if(t> && tran[t-] == tran[i])
{
res[t-] += res[i];
}
else
{
res[t] = res[i];
tran[t++] = tran[i];
}
}
}
num = t;
ans ++;
}
cout<<ans<<endl;
}
return ;
}

Codeforces 909 D. Colorful Points (模拟)的更多相关文章

  1. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  2. Codeforces Round #455 (Div. 2) 909D. Colorful Points

    题 OvO http://codeforces.com/contest/909/problem/D CF 455 div2 D CF 909D 解 算出模拟的复杂度之后就是一个很水的模拟题 把字符串按 ...

  3. CodeForces 909D Colorful Points

    题解: 暴力,模拟. 把字符串压缩一下,相同的处理成一位,记录下个数,然后暴力模拟即可. #include <bits/stdc++.h> using namespace std; con ...

  4. Codeforces 909 substr用法 思维合并线段目标最少 Py语句逆推DP vecrtor缩点删不同颜色点模拟 拓扑排序处理任务

    A str.substr(i,j) 从str[i]开始起取j个字符作为返回的字符串 /* Huyyt */ #include <bits/stdc++.h> using namespace ...

  5. Codeforces909D Colorful Points(缩点)

    http://codeforces.com/problemset/problem/909/D 直接模拟超时.要运用缩点的方法,把相同的一段缩成一点,记录有几个. 对于非首尾的缩点每次-2,首尾的-1. ...

  6. Codeforces 747C:Servers(模拟)

    http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...

  7. Codeforces 740A. Alyona and copybooks 模拟

    A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...

  8. Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  9. CodeForces 670 A. Holidays(模拟)

    Description On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Ma ...

随机推荐

  1. C#获取文件路径的几种方法

    //获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称. string str5=Application.StartupPath;//可获得当前执行的exe的文件名. string str1 ...

  2. iOS8 生成二维码与条形码

    iOS8 生成二维码与条形码 效果图: 源码: // // ViewController.m // CodeCreator // // Created by YouXianMing on 15/3/1 ...

  3. Sublime Text 3 调用cmd运行c、java、python、batch file

    一.调用cmd运行c(首先复制MinGW到C盘根目录,并添加环境变量) Tools --> Build System --> New Build System 删除所有内容 复制如下代码进 ...

  4. 铁乐学python_day24_面向对象进阶1_内置方法

    铁乐学python_day24_面向对象进阶1_内置方法 题外话1: 学习方法[wwwh] what where why how 是什么,用在哪里,为什么,怎么用 学习到一个新知识点的时候,多问问上面 ...

  5. __iter__的有无

    迭代器和生成器 1.迭代器 我们之前⼀直在⽤可迭代对象进⾏迭代操作. 那么到底什么是可迭代对象.⾸先我们先回顾⼀下⽬前我们所熟知的可迭代对象有哪些: str, list, tuple, dict, s ...

  6. 占位符 %s

    a = input("Name:")b = input("Age:")c = input("Job:")d = input("ho ...

  7. 【ORACLE】 安装需要注意的问题(一)

    安装ORACLE虽然不是很难,但是有时候很容易因为一些小细节导致安装失败,浪费大量的时间. 这里总结一下安装ORACLE的时候需要注意的问题,以及解决的办法 问题1:系统先决条件检查 正在检查操作系统 ...

  8. 关于安装AndroidStudio中遇见的问题

    安装AndroidStudio: 最近,准备了解下Android,就买了本<第一行代码Android:第二版>, 最开始就是安装AndroidStudio,刚开始以为安装的挺容易的,结果… ...

  9. Keepalived 实现双机热备

    原理 首先有一个虚拟ip暴露给客户端,虚拟ip对应的mac地址为一台真实服务器, 即用户向虚拟ip发送一个请求,该请求会被分发到真实服务器上. 现在有2台真实服务器,一台master,一台backup ...

  10. singleton和prototype的区别

    singleton作用域:当把一个Bean定义设置为singleton作用域是,Spring IoC容器中只会存在一个共享的Bean实例,并且所有对Bean的 请求,只要id与该Bean定义相匹配,则 ...