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 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)的更多相关文章
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #455 (Div. 2)
Codeforces Round #455 (Div. 2) A. Generate Login 题目描述:给出两个字符串,分别取字符串的某个前缀,使得两个前缀连起来的字符串的字典序在所有方案中最小, ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- 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 ...
- 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 ...
- Codeforces Round #425 (Div. 2))——A题&&B题&&D题
A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...
- Codeforces Round #579 (Div. 3) 套题 题解
A. Circle of Students 题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
- Codeforces Round #426 (Div. 2)A题&&B题&&C题
A. The Useless Toy:http://codeforces.com/contest/834/problem/A 题目意思:给你两个字符,还有一个n,问你旋转n次以后从字符a变成b,是顺时 ...
随机推荐
- 洛谷P2178 [NOI2015]品酒大会 后缀数组+单调栈
P2178 [NOI2015]品酒大会 题目链接 https://www.luogu.org/problemnew/show/P2178 题目描述 一年一度的"幻影阁夏日品酒大会" ...
- 剑指offer24:二叉树中和为输入整数值的所有路径。(注意: 在返回值的list中,数组长度大的数组靠前)
1 题目描述 输入一颗二叉树的根节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径.(注意: 在返回值的list中,数组长 ...
- python学习-7 条件语句 while循环 + 练习题
1.死循环 while 1 == 1: print('ok') 结果是一直循环 2.循环 count = 0 while count < 10: print(count) count = cou ...
- spark异常篇-Removing executor 5 with no recent heartbeats: 120504 ms exceeds timeout 120000 ms 可能的解决方案
问题描述与分析 题目中的问题大致可以描述为: 由于某个 Executor 没有按时向 Driver 发送心跳,而被 Driver 判断该 Executor 已挂掉,此时 Driver 要把 该 Exe ...
- 利用神器BTrace 追踪线上 Spring Boot应用运行时信息
概述 生产环境中的服务可能会出现各种问题,但总不能让服务下线来专门排查错误,这时候最好有一些手段来获取程序运行时信息,比如 接口方法参数/返回值.外部调用情况 以及 函数执行时间等信息以便定位问题.传 ...
- C# 连接 Socks5 代理
public class Socks5ProxyHelp { private Socks5ProxyHelp() { } public static string[] errorMsgs = { &q ...
- MyEclipse优化攻略搜集
1 首先内存设置 不会报讨厌的内存溢出out of memory 和 henp space 在 myeclipse.ini把大小调成一样是因为不让myeclipse频繁的换内存区域的大小. #utf8 ...
- html5中本地存储概念是什么?
html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage.sessionStorage用于本地存储一个会话中的数据,这些数据只有在同一个会话中的页 ...
- Linux下mysql不区分大小写设置
Linux环境下的MySQL数据库的表名默认是区分大小写的 Windows环境下的MySQL数据库的表名默认是不区分大小写的 所以Linux下想mysql不区分下大写可以查看/etc/my.cnf文件 ...
- Lab3 Report