题目链接: 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. 用NSOperation写下载队列

    用NSOperation写下载队列 说明 1. 支持缓存机制 2. 图片都是在主线程中加载 3. 文件名用了md5加密 *这东西被人写烂了,但大伙如果对NSOperation不熟悉的话,可以看看本人的 ...

  2. Git提交代码自动触发JenKins构建项目

    1.需求场景 用户提交代码后自动触发jenkins构建项目 流程图如下: 2.JenKins安装Gitlab Hook Plugin插件 3.JenKins配置 4.Gitlab Hook Plugi ...

  3. 《编程题》穷举法求N年后有多少头牛

    若一头小母牛,从出生起第四个年头开始每年生一头母牛,按这个规律,第N年时有多少头母牛? #include <iostream> int main(int argc, const char ...

  4. 铁乐学Python_day06-整数和字符串小数据池

    python小数据池(内存地址) 今天来学习认识一下python中的小数据池. 我们都知道 ==是用来作比较,要是两个变量的数值相等, 用==比较返回的bool值会是True: a = 1000 b ...

  5. Springboot 设置session超时

    使用版本 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring ...

  6. Promise & Deferred objects in JavaScript Pt.1: Theory and Semantics.

    原文:http://blog.mediumequalsmessage.com/promise-deferred-objects-in-javascript-pt1-theory-and-semanti ...

  7. 使用ubuntu desktop是可能会用到的配置

    1.ubuntu desktop12.04 接双显示器 想要12.04版本在接上双显示器时能很好的工作,则需要进行如下设置: (1).编辑/etc/X11/xorg.conf文件: /etc/X11/ ...

  8. 解决redis-cli command not found问题

    在使用其他服务器连接Redis服务器时,一般使用的语句是 [redis-cli -h IP -p port] 但是早上连接时报错:redis-cli command not found 在redis服 ...

  9. 2038. [国家集训队]小Z的袜子【莫队】

    Description 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命…… 具体来说,小Z把这N只 ...

  10. 【bzoj 4066】 简单题

    题目 显然这就是让我们在二维上数个点 如果没有强制在线就随便做啦,扫描线+主席树应该是最好的选择 但是现在强制在线并且卡了树套树的空间,于是只能上\(kdt\)了 我们还是维护一下每个子树分割出来的矩 ...