题目链接: 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. Office 365 Pass-through身份验证及Seamless Single Sign-On

    Hello 小伙伴们, 这篇文章将视点聚焦在传递身份验证(Pass-through Authentication)上,将分享如何安装,配置和测试Azure Active Directory(Azure ...

  2. September 24th 2017 Week 39th Sunday

    To live is the rarest thing in the world. Most people exist. That is all. 生活是世间最罕见的事情:生存,却是世间最常见的事情: ...

  3. VM下,装centos7系统,配置nginx的问题

    一.流程 1.先安装nginx依赖的包 (1)yum install gcc-c++ (2)yum install -y pcre pcre-devel (3)yum install -y zlib ...

  4. POJ 3294 Life Forms [最长公共子串加强版 后缀数组 && 二分]

    题目:http://poj.org/problem?id=3294 Life Forms Time Limit: 5000MS   Memory Limit: 65536K Total Submiss ...

  5. virtualbox+vagrant学习-2(command cli)-15-vagrant resume命令

    Resume 格式: vagrant resume [vm-name] 这将恢复先前挂起的vagrant托管计算机,可能与suspend命令一起使用. 默认情况下,配置的预配置程序在运行该命令时将不再 ...

  6. etherlime-2-Etherlime Library API-deployer

    Etherlime Library API 库API Deployer部署者 Deployer functionality The main functionality the deployer ex ...

  7. Python读文件报错:SyntaxError: Non-ASCII character in file

    打开city.py文件时报错 问题原因: 程序中的编码错误,python默认是acii模式,没有支持utf8.如果代码中有汉字 ,就会报错 解决方案: 源代码文件(city.py)第一行添加:#cod ...

  8. [转]打造自己的LINQ Provider(上):Expression Tree揭秘

    概述 在.NET Framework 3.5中提供了LINQ 支持后,LINQ就以其强大而优雅的编程方式赢得了开发人员的喜爱,而各种LINQ Provider更是满天飞,如LINQ to NHiber ...

  9. ddt 接口框架数据处理调用excel 处理

    之前在csdn写过这里就不赘述了: https://blog.csdn.net/chen498858336/article/details/84351146

  10. hibernate -- 注解映射实体和表

    表名的映射 //代表此类参与ORM映射,此注解必须要有 @Entity //代表user这个类映射了一个表user50,如果表名和类名一样,此注解可以省略 @Table(name="user ...