http://codeforces.com/problemset/problem/909/D

直接模拟超时。要运用缩点的方法,把相同的一段缩成一点,记录有几个。

对于非首尾的缩点每次-2,首尾的-1。

注意strlen不要放循环里,因为这个超时找了好久。。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 0x3f3f3f3f
#define MAXN 500010
const int MOD=1e9+;
typedef long long ll;
using namespace std;
typedef struct{
char c;
int num;
}Node;
Node node[];
char ss[];
int len;
int update(int len)
{
int j=, flag = ;
for(int i = ; i < len; i++){
if(node[i].num>){//该点还有几个
if(!flag){//第一次找到,直接赋给node[0]
flag = ;
node[j] = node[i];
}
else if(node[i].c == node[j].c){
node[j].num += node[i].num;
}
else{
node[++j] = node[i];
}
}
}
return j;
}
int solve()
{
int len = update(strlen(ss))+, cnt=;//第一次update用的是缩点前长度,得到缩点后长度
while(len>){
for(int i = ;i < len-; i++){
node[i].num -= ;
}
node[].num--; node[len-].num--;
len = update(len)+;
cnt++;
}
return cnt;
}
int main()
{
IO;
cin >> ss;
int len = strlen(ss);
for(int i = ; i < len; i++){//注意,循环里不要放strlen!!会很耗很耗时
node[i].c = ss[i];
node[i].num = ;
}
cout << solve() << endl;
return ;
}

Codeforces909D Colorful Points(缩点)的更多相关文章

  1. Codeforces 909 D. Colorful Points (模拟)

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

  2. CodeForces 909D Colorful Points

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

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

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

  4. Codeforces Round #455 (Div. 2)

    Codeforces Round #455 (Div. 2) A. Generate Login 题目描述:给出两个字符串,分别取字符串的某个前缀,使得两个前缀连起来的字符串的字典序在所有方案中最小, ...

  5. Codeforces Round #455

    Generate Login 第二个单词肯定只取首字母 Solution Segments 从1开始的线段和在n结束的线段各自凑一凑,剩下的转化为规模为n-2的子问题. Solution Python ...

  6. 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 ...

  7. Codeforces Round #286 (Div. 1) D. Mr. Kitayuta's Colorful Graph 并查集

    D. Mr. Kitayuta's Colorful Graph Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/ ...

  8. BZOJ 1051: [HAOI2006]受欢迎的牛 缩点

    1051: [HAOI2006]受欢迎的牛 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/ ...

  9. ITU-T G.1081 IPTV性能监测点 (Performance monitoring points for IPTV)

    ITU-T 建议书 G.1081 IPTV性能监测点 Performance monitoring points for IPTV Summary Successful deployment of I ...

随机推荐

  1. 移动端根据不同DPR加载大小不同的图片

    1.首先创建mixin.styl文件代码如下: bg-image($url) // 创建bg-image($url)函数 background-image: url($url + "@2x. ...

  2. 【UOJ 209】【UER #6】票数统计

    题解: jls的题目还是比较好的 首先比较显然我们可以分析出 当x<y时,显然只能满足前缀条件 针对这一档部分分,是个简单的组合数 考虑一下后缀限制,发现真的不好搞.. 看了题解发现,枚举总共的 ...

  3. 【BZOJ3697】采药人的路径

    题解: 比较简单的点分治 首先暴力的话直接枚举 然后枚举另一个点的时候顺便看一下有没有零点 n^2 考虑点分治 分治之后用f[i][0/1]表示权值为i,有没有零点的方案数 我们来证明一件事情,如果两 ...

  4. 流程图 Graphviz - Graph Visualization Software

    0.目录 1.参考 https://www.processon.com/  应该值得一试 知乎 用什么软件画流程图? 9款国内外垂直领域的在线作图工具[可代替visio] 程序员必知的七个图形工具 说 ...

  5. OAuth2:客户端证书授权(Client Credentials)类型的开放授权

    适应范围 认证服务器不提供像用户数据这样的重要资源,仅仅是有限的只读资源或者一些开放的API.例如使用了第三方的静态文件服务,如Google Storage或Amazon S3.这样,你的应用需要通过 ...

  6. 需求:lr需要在一串数字中随机位置插入一个新数字的实现方式

    效果如下: 需要用到sscanf()函数:  从一个字符串中读进与指定格式相符的数据. Action() { ],s2[],s3[]; int n=atoi(lr_eval_string(" ...

  7. Codeforces 311D Interval Cubing 数学 + 线段树 (看题解)

    Interval Cubing 这种数学题谁顶得住啊. 因为 (3 ^ 48) % (mod - 1)为 1 , 所以48个一个循环节, 用线段树直接维护. #include<bits/stdc ...

  8. k8s教程

    k8s教程地址 安装https://github.com/gjmzj/kubeaszhttps://github.com/opsnull/follow-me-install-kubernetes-cl ...

  9. 给定两个字符串 s 和 t,它们只包含小写字母。 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。 请找出在 t 中被添加的字母。

    给定两个字符串 s 和 t,它们只包含小写字母.字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母.请找出在 t 中被添加的字母. 示例: 输入: s = "abcd" ...

  10. scrapy 代码调试用 shell

    在虚拟机里CD到你的scrapy某个项目的目录,再 1. scrapy shell + '网址'(注意引号) 2. response.xpath(' ')来提取 如: response.xpath(' ...