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. 未在本地计算机上注册“OraOLEDB.Oracle.1”提供程序。

     问题描述:运行访问oracle数据库的.net程序时,弹出错误"未在本地计算机上注册“OraOLEDB.Oracle.1”提供程序". 系统环境:windows server 2 ...

  2. 通过ping命令查看服务器是linux还是windows系列

    通过ping命令识别服务器类型

  3. python 链接数据库错误

    用python3链接oracle产生错误: DPI-1047: Cannot locate a 64-bit Oracle Client library: "The specified mo ...

  4. BZOJ2821 作诗(Poetize) 主席树 bitset

    原文链接https://www.lydsy.com/JudgeOnline/problem.php?id=2821 题目传送门 - BZOJ2821 题意 $n$ 个数,$m$ 组询问,每次问 $[l ...

  5. ConcurrentModificationException(并发修改异常)的分析

    1)介绍 并发修改ConcurrentModificationException错误是开发中一个常见错误,多发生在对一个Collection边遍历边做影响size变化的操作中,下面以ArrayList ...

  6. MySQL高级01

    MySQL支持大型数据库,支持5000万条记录的数据仓库,32位系统表文件最大可支持4GB,64位系统支持最大的表文件为8TB. 官网下载地址:http://dev.mysql.com/downloa ...

  7. html-form

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. HTML文本结构及常用标签

    一.什么是HTML? HTML:超文本标签语言 (Hyper Text Markup Language) www万维网的描述性语言. XHTML指可扩展超文本标记语言(标识语言)(EXtensible ...

  9. 每月学习数理统计--《统计学习方法—李航》(3): SVM

    1. SVM的最优化问题 2.拉格朗日乘数法,对偶条件KKT条件 3.软件隔支持向量机 4.非线性支持向量机,核函数 5.SMO算法 1. SVM的最优化问题 支持向量机(Support Vector ...

  10. Mybatis之占位符与拼接符

    1.占位符 1.1  含义: 在持久化框架中,为了将约束条件中的可变参数从sql中分离出来,在原有的参数位置使用特殊的标记来标记该位置,后期通过代码给sql传递参数(即实现sql与代码分离开).这个特 ...