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. lvs-ldirectord

    Ldirectord;用来对后端服务器的检测状态后并进行操作  安装在director上 对后端的rs服务器的 健康检查包括几方面: 1通过ping 若可以ping到服务器表示主机活着 2 对端口的检 ...

  2. Python学习(十四) —— 并发编程

    一.进程的概念 进程即正在执行的一个过程,进程是对正在运行的程序的一个抽象. 进程的概念起源于操作系统,是操作系统最核心的概念.操作系统的其它所有内容都是围绕进程的概念展开的. #必备的理论基础 #一 ...

  3. sql查询一个字段不同值并返回

    sql SELECT COUNT(字段),分组字段,SUM(字段),SUM(字段) FROM 表 GROUP BY 分组字段 java EntityWrapper<ProjectEntity&g ...

  4. There is no setter for property named 可能产生的原因!

     There is no setter for property named 'operateIP ' in 'class com.chinaunicom.wsp.facade.entity.User ...

  5. Web服务API

    Web服务API     内容 [ 隐藏 ]  1 概述 2个 services.php 3 详细教程 4 例子 5 另见 概观 Web服务API允许您将插件的功能(通常是外部函数)公开为Web服务. ...

  6. springmvc接受前端的参数封装成对象

    前端如果传过来的是json格式的字符串,后台参数需要加@RequestBody注解. 前端如果传过来的是json对象,后台不参数需要加@RequestBody注解. $.POST({ url: url ...

  7. supervisor 监控redis & mongodb

    安装 安装python brew install python 安装pipwget https://bootstrap.pypa.io/get-pip.pysudo python get-pip.py ...

  8. 搭建JMETER+ANT自动化接口测试环境步骤(一)

    一.环境准备: 1.JDK    下载            地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html ...

  9. LYOI 2016 Summer 函数 【线段树】

    <题目链接> 题目大意: fqk 退役后开始补习文化课啦,于是他打开了数学必修一开始复习函数,他回想起了一次函数都是 f(x)=kx+b的形式,现在他给了你n个一次函数 fi(x)=kix ...

  10. POJ 1988 Cube Stacking 【带权并查集】

    <题目链接> 题目大意: 有几个stack,初始里面有一个cube.支持两种操作: 1.move x y: 将x所在的stack移动到y所在stack的顶部. 2.count x:数在x所 ...