Codeforces 909 D. Colorful Points (模拟)
题目链接: 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 (模拟)的更多相关文章
- CodeForces.158A Next Round (水模拟)
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
- Codeforces Round #455 (Div. 2) 909D. Colorful Points
题 OvO http://codeforces.com/contest/909/problem/D CF 455 div2 D CF 909D 解 算出模拟的复杂度之后就是一个很水的模拟题 把字符串按 ...
- CodeForces 909D Colorful Points
题解: 暴力,模拟. 把字符串压缩一下,相同的处理成一位,记录下个数,然后暴力模拟即可. #include <bits/stdc++.h> using namespace std; con ...
- Codeforces 909 substr用法 思维合并线段目标最少 Py语句逆推DP vecrtor缩点删不同颜色点模拟 拓扑排序处理任务
A str.substr(i,j) 从str[i]开始起取j个字符作为返回的字符串 /* Huyyt */ #include <bits/stdc++.h> using namespace ...
- Codeforces909D Colorful Points(缩点)
http://codeforces.com/problemset/problem/909/D 直接模拟超时.要运用缩点的方法,把相同的一段缩成一点,记录有几个. 对于非首尾的缩点每次-2,首尾的-1. ...
- Codeforces 747C:Servers(模拟)
http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...
- Codeforces 740A. Alyona and copybooks 模拟
A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...
- 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 ...
- CodeForces 670 A. Holidays(模拟)
Description On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Ma ...
随机推荐
- XtraEditors二、ComboBox、ComboBoxEdit、CheckedComboBoxEdit
https://documentation.devexpress.com/WindowsForms/DevExpress.XtraEditors.ComboBoxEdit.class 1.使用Winf ...
- FTP工具FileZilla&WinSCP与FTP类库FluentFTP
FileZilla Filezilla分为client和server.其中FileZilla Server是Windows平台下一个小巧的第三方FTP服务器软件,系统资源也占用非常小,可以让你快速简单 ...
- #001 如何组织JS代码
如何组织JS代码 有没有这样的经历,在编写代码的时候,因为功能简单,写的时候比较随意,所有的JS代码都放在一个文件里面,但是随着功能的增加,发现代码很乱,不好维护. 简单的整理了一下,目前对已有项目的 ...
- 盒子模型之margin相关技巧!
废话不多说,直接进入主题,margin相关技巧. 1.设置元素水平居中:margin:x auto; 2.margin负值让元素位移及边框合并. 外边距合并 指当两个垂直外边距相遇时,它们将形成一个外 ...
- Cent OS home下中文目录改成英文目录
如果安装了中文版的Cent OS之后,root目录和home目录下会出现中文的路径名,如“桌面”.“文档”.“图片”.“公共的”.“下载”.“音乐”.“视频”等目录,这样在命令行上操作十分的不方便,需 ...
- Python3中内置类型bytes和str用法及byte和string之间各种编码转换
Python 3最重要的新特性大概要算是对文本和二进制数据作了更为清晰的区分.文本总是Unicode,由str类型表示,二进制数据则由bytes类型表示.Python 3不会以任意隐式的方式混用str ...
- c# 匿名函数与托付
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/han_yankun2009/article/details/26290779 在 2.0之前的 ...
- [Java123]Gradle
https://dzone.com/articles/gradle-vs-maven https://docs.gradle.org/current/userguide/what_is_gradle. ...
- ASP.NET MVC编程——路由
框架自动生成的路由配置 上图中,路由配置文件为App_Start文件夹下的RouteConfig.cs. 代码如下: public class RouteConfig { public static ...
- flex布局中flex-shrink的计算规则
下面代码来自MDN html部分: <p>the width of content is 500px, flex-basic of flex item is 120px.</p> ...