Codeforces909D Colorful Points(缩点)
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(缩点)的更多相关文章
- Codeforces 909 D. Colorful Points (模拟)
题目链接: Colorful Points 题意: 给出一段字符串(长度最大为1e6),每次操作可以删除字符串中所有相邻字符与其不同的字符.例如:aabcaa 删除一次就变成了aa,就无法再删除了.题 ...
- CodeForces 909D Colorful Points
题解: 暴力,模拟. 把字符串压缩一下,相同的处理成一位,记录下个数,然后暴力模拟即可. #include <bits/stdc++.h> using namespace std; con ...
- Codeforces Round #455 (Div. 2) 909D. Colorful Points
题 OvO http://codeforces.com/contest/909/problem/D CF 455 div2 D CF 909D 解 算出模拟的复杂度之后就是一个很水的模拟题 把字符串按 ...
- Codeforces Round #455 (Div. 2)
Codeforces Round #455 (Div. 2) A. Generate Login 题目描述:给出两个字符串,分别取字符串的某个前缀,使得两个前缀连起来的字符串的字典序在所有方案中最小, ...
- Codeforces Round #455
Generate Login 第二个单词肯定只取首字母 Solution Segments 从1开始的线段和在n结束的线段各自凑一凑,剩下的转化为规模为n-2的子问题. Solution Python ...
- 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 ...
- 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/ ...
- BZOJ 1051: [HAOI2006]受欢迎的牛 缩点
1051: [HAOI2006]受欢迎的牛 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/ ...
- 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 ...
随机推荐
- 洛谷---小L和小K的NOIP考后放松赛
链接: https://www.luogu.org/contestnew/show/11805?tdsourcetag=s_pcqq_aiomsg 题解: 没人过的题我就没看 t2: 考虑每个点是朋友 ...
- 【bzoj4976】宝石镶嵌
题解: 比较水 注意k<=100这个条件 当n-k比较大的时候 我们显然会把它有的位都给取了 不然的话我们可以考虑dp 暴力状压就可以了 代码: #include <bits/stdc++ ...
- zabbix通过自动发现tomcat应用端口监控连接数
192.168.10.98上 netstat -anp | wc -l netstat -anp|grep 8094 | grep ESTABLISHED | wc -l netstat -anp|g ...
- python--闭包、装饰器
1.闭包 ①.python中一切皆对象,函数中嵌套函数肯定也是合理的,这种函数也叫作内嵌函数(内部函数) ②.内嵌函数只能被外部函数调用,被外部函数以外的区域被调用,就会出错!!! ③.若内部函数中引 ...
- BZOJ2534 Uva10829L-gap字符串 字符串 SA ST表
原文链接https://www.cnblogs.com/zhouzhendong/p/9240665.html 题目传送门 - BZOJ2534 题意 有一种形如 $uvu$ 形式的字符串,其中 $u ...
- Practice| 流程控制
若整数a除以非零整数b,商为整数,且余数为零, 我们就说a能被b整除(或说b能整除a),a为被除数,b为除数,即b|a("|"是整除符号),读作"b整除a"或& ...
- 057 Java中kafka的Producer程序实现
1.需要启动的服务 这里启动的端口是9092. bin/kafka-console-consumer.sh --topic beifeng --zookeeper linux-hadoop01.ibe ...
- HTML的5种空格表示
HTML提供了5种空格实体(space entity),它们拥有不同的宽度,非断行空格( )是常规空格的宽度,可运行于所有主流浏览器.其他几种空格( )在不同浏览器中宽度各异. ...
- Java中的不同遍历方式
已知一个Person类: public class Person implements Comparable<Person>{ String name; String id; public ...
- go编译go-gtk,出现invalid flag in pkg-config --libs: -Wl,-luuid提示
go编译go-gtk 使用go编译go-gtk,直接编译会出现错误: pkg-config --cflags -- gdk-2.0 gthread-2.0 pkg-config --l ...