D. Colorful Points

You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right.

You perform a sequence of operations on this set of points. In one operation, you delete all points which have a neighbor point of a different color than the point itself. Points are deleted simultaneously, i.e. first you decide which points have to be deleted and then delete them. After that you can perform the next operation etc. If an operation would not delete any points, you can't perform it.

How many operations will you need to perform until the next operation does not have any points to delete?

Input
Input contains a single string of lowercase English letters 'a'-'z'. The letters give the points' colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc.

The number of the points is between 1 and 106.

Output
Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete.

Input

aabb

Output


Input

aabcaa

Output


思路:模拟一下

AC代码:

 #include<bits/stdc++.h>

 using namespace std;
vector< pair<int,int> > v;
int main(){
string str;
cin>>str;
int num=;
int flag=;
for(int i=;i<=str.size();i++){
if(str[i]!=str[i+]&&(i+)<str.size()){
flag=;
}
if(str[i]!=str[i+]){
v.push_back(make_pair(str[i]-'a',num));
num=;
}else{
num++;
}
}
if(flag){
printf("");
return ;
}
/*vector<pair<int,int> > ::iterator it;
for(it=v.begin();it!=v.end();it++){
cout<<(*it).first<<" "<<(*it).second<<endl;
}
*/
int ans=;//aabcaa while(){
vector<pair<int,int> > ::iterator it;
for(it=v.begin();it!=v.end();it++){
if(it==v.begin()||it==(v.end()-)){
(*it).second--;
continue;
}else{
(*it).second-=;
}
}
vector<pair<int,int> > ::iterator xit;
/*for(xit=v.begin();xit!=v.end();xit++){
cout<<(*xit).first<<" "<<(*xit).second<<endl;
}
*/
vector< pair<int,int> > temp;
vector<pair<int,int> > ::iterator itt;
for(itt=v.begin();itt!=(v.end());itt++){
if((*itt).second>){
if(temp.size()==){
temp.push_back(make_pair((*itt).first,(*itt).second));
}else{
vector<pair<int,int> > ::iterator t=temp.end()-;
if((*itt).first==(*t).first){
(*t).second+=(*itt).second;
}else{
temp.push_back(make_pair((*itt).first,(*itt).second));
}
}
}
}
/*vector<pair<int,int> > ::iterator flag=temp.begin(); cout<<temp.size()<<endl;
for(;flag!=temp.end();flag++){
cout<<(*flag).first<<" "<<(*flag).second<<endl;
}
*/
ans++;
if(temp.size()<=){
break;
}else{
v=temp;
} }
cout<<ans<<endl;
return ;
} /* aabbaaa */

Codeforces Round #455 (Div. 2) D题(花了一个早自习补了昨晚的一道模拟QAQ)的更多相关文章

  1. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  2. Codeforces Round #455 (Div. 2)

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

  3. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  4. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  5. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

  6. Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

    Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...

  7. Codeforces Round #425 (Div. 2))——A题&&B题&&D题

    A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...

  8. Codeforces Round #579 (Div. 3) 套题 题解

    A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...

  9. Codeforces Round #426 (Div. 2)A题&&B题&&C题

    A. The Useless Toy:http://codeforces.com/contest/834/problem/A 题目意思:给你两个字符,还有一个n,问你旋转n次以后从字符a变成b,是顺时 ...

随机推荐

  1. HTNL基础之二

    HTML实体字符 “<”:< “>”:> “空格”: ' / / '  “"”:"  “®”:®  “©”:© 列表 ①无序列表:列表用来在网页上组织信息, ...

  2. ES6——入门学习指南

    ES6的简介: ECMAScript6.0(以下简称ES6)是JavaScript语言的下一代标准,已在2015年6月正式发布了.它的目标,是使得JavaScript语言可以用来编写复杂的大型应用程序 ...

  3. 由[].slice.call()引发的思考

    由[].slice.call()引发的思考   经常看到大家用[].slice.call()或者Array.prototype.slice.call():  我一直是一知半解的,今天算是基本弄清楚了, ...

  4. 01 Java 内存分配全面浅析

    http://blog.csdn.net/shimiso/article/details/8595564 Java 内存分配全面浅析  本文将由浅入深详细介绍Java内存分配的原理,以帮助新手更轻松的 ...

  5. Java内存管理-探索Java中字符串String(十二)

    做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开! 一.初识String类 首先JDK API的介绍: public final class String extends O ...

  6. Tag Helper1

    Tag Helpers是服务器段的C#代码,在Razor文件里,参与到创建和渲染HTML元素的过程 和HTML Helpers类似 跟HTML的命名规范一致 内置了很多Tag Helpers也可以自定 ...

  7. 【原创】大叔经验分享(83)impala执行多个select distinct

    impala在一个select中执行多个count distinct时会报错,比如执行 select key, count(distinct column_a), count(distinct col ...

  8. [转]TCP的三次握手与四次挥手

    TCP的概述 TCP把连接作为最基本的对象,每一条TCP连接都有两个端点,这种断点我们叫作套接字(socket),它的定义为端口号拼接到IP地址即构成了套接字,例如,若IP地址为192.3.4.16 ...

  9. Django:forms局部函数、cookie、sesion、auth模块

    一.forms组件 二.cookie和session组件 三.auth组件 一.forms组件 1.校验字段功能 针对一个实例:注册用户讲解 模型:models class UserInfo(mode ...

  10. ftp服务器终端登录后乱码处理方法

    首先在windows上用资源管理器登录看看会不会乱码,如果不会,说明是GBK编码 因为windows默认是GBK(936),linux默认(UTF-8) 因为FTP服务器我们修改不了,如果用linux ...