Plasticine zebra
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.

Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.

Before assembling the zebra Grisha can make the following operation 00 or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".

Determine the maximum possible length of the zebra that Grisha can produce.

Input

The only line contains a string ss (1≤|s|≤1051≤|s|≤105, where |s||s| denotes the length of the string ss) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.

Output

Print a single integer — the maximum possible zebra length.

Examples
input

Copy
bwwwbwwbw
output

Copy
5
input

Copy
bwwbwwb
output

Copy
3
Note

In the first example one of the possible sequence of operations is bwwwbww|bw →→ w|wbwwwbwb →→ wbwbwwwbw, that gives the answer equal to 55.

In the second example no operation can increase the answer.

题意:没有连续的b和w的字符串为zebra length,求一个字符串的zebra length最长长度,字符串可变化:将字符串分成两部分然后倒置每部分组成新的字符串

分析:考虑字符串的变化:将字符串分为前缀和后缀两部分,字符串的变化就是将后缀倒置前缀倒置

  考虑将两个一样的字符串连接在一起得到新字符串,则新字符串的子串包含了原来一个字符串的所有变化

AC代码:

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e6+10;
const ll mod = 998244353;
const double pi = acos(-1.0);
const double eps = 1e-8;
map<string,ll> mp;
string s;
int main() {
ios::sync_with_stdio(0);
cin >> s;
string ts = "";
ts = s + s;
ll ans = 1, maxans = -1;
for( ll i = 0; i < ts.length(); i ++ ) {
if( i == 0 ) {
continue;
}
if( ts[i] != ts[i-1] ) {
ans ++;
if( i == ts.length()-1 ) {
maxans = max(maxans,ans);
}
} else {
maxans = max(maxans,ans);
ans = 1;
}
}
if( maxans > s.length() ) {
maxans = maxans - s.length();
}
cout << maxans << endl;
return 0;
}

  

CF1025C Plasticine zebra 思维 字符串的更多相关文章

  1. CF1025C Plasticine zebra【环状字符串/思维】

    给你一个长度为 \(\left|s\right|\) 的01串 \(s\) ,每次操作你可以任选一个 \(k\) ,使01串的 \([1,k]\) 和 \((k,\left|s\right|]\) 分 ...

  2. CF1025C Plasticine zebra

    思路: 不要被骗了,这个操作实际上tm是在循环移位. 实现: #include <bits/stdc++.h> using namespace std; int main() { stri ...

  3. codeforces#505--C Plasticine Zebra

    C. Plasticine zebra time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. CF C. Plasticine zebra (思维)

    题意: 是输入一个只有'w','b'的字符串,可以对他的任意位置切割成两个子串,切割后的右边的子串翻转后再和左边的子串拼起来会得到一个新的字符串,操作次数不限,问能得到的字符串中wb交替出现的最大的长 ...

  5. 【CF1025C】Plasticine zebra(模拟)

    题意: n<=1e5 思路:可以证明答案即为极长交替出现的串长度之和 需要注意其实这个串是一个环,复制后再做 #include<cstdio> #include<cstring ...

  6. Codeforces 219C Color Stripe(思维+字符串)

    题目链接:http://codeforces.com/problemset/problem/219/C 题目大意: 给出一个字符串,只包含k种字符,问最少修改多少个字符(不增长新的种类)能够得到一个新 ...

  7. Codeforces #505(div1+div2) C Plasticine zebra

    题意:给你一段字符串,可以选择任意多的位置,每个位置会反转两边的字符串,问交错的字符串最长是多长? 思路:找规律,仔细分析样例1.假设位置为 1 2 3 4 5 6 7 8 9,反转之后会发现答案是7 ...

  8. CF 1025C Plasticine zebra

    昨晚忘记判只有一个字符的情况fst了呜呜呜 挺有趣的题,昨晚连刚带猜弄出结论 考虑答案的取值,最优答案可能是一个后缀,或者是一个前缀,或者是一个后缀加上前缀 那么翻转之后最优答案的可选值就有了1的前缀 ...

  9. 牛客小白月赛4 B 博弈论 思维 字符串

    链接:https://www.nowcoder.com/acm/contest/134/B来源:牛客网 题目描述 铁子和顺溜在学习了博弈论的sg函数之后,解决了很多很多博弈题,现在他们遇到了一道难题. ...

随机推荐

  1. HashMap、Hash Table、ConcurrentHashMap

    这个这个...本王最近由于开始找实习工作了,所以就在牛客网上刷一些公司的面试题,大多都是一些java,前端HTML,js,jquery,以及一些好久没有碰的算法题,说实话,有点难受,其实在我不知道的很 ...

  2. java遍历所有目录和文件

    package xian; import java.io.File; import java.util.ArrayList; public class GetFile { private static ...

  3. 分布式ID系列之为什么需要分布式ID以及生成分布式ID的业务需求

    为什么需要分布式id生成系统 在复杂分布式系统中,往往需要对大量的数据和消息进行唯一标识.如在美团点评的金融.支付.餐饮.酒店.猫眼电影等产品的系统中,数据日渐增长,对数据分库分表后需要有一个唯一ID ...

  4. containerd与kubernetes集成

    kubernetes集群三步安装 概念介绍 cri (Container runtime interface) cri is a containerd plugin implementation of ...

  5. (14)ASP.NET Core 中的日志记录

    1.前言 ASP.NET Core支持适用于各种内置和第三方日志记录提供应用程序的日志记录API.本文介绍了如何将日志记录API与内置提供应用程序一起使用. 2.添加日志提供程序 日志记录提供应用程序 ...

  6. Shiro权限管理框架(三):Shiro中权限过滤器的初始化流程和实现原理

    本篇是Shiro系列第三篇,Shiro中的过滤器初始化流程和实现原理.Shiro基于URL的权限控制是通过Filter实现的,本篇从我们注入的ShiroFilterFactoryBean开始入手,翻看 ...

  7. 微信小程序云开发报错解决: Setting data field "openid" to undefined is invalid.

    最近在学习微信小程序云开发,刚一开始就遇到了问题. 点击获取openid的时候控制台开始报错: [云函数] [login] user openid:  undefined VM97:1 Setting ...

  8. 重学计算机组成原理(五)- "旋转跳跃"的指令实现

    CPU执行的也不只是一条指令,一般一个程序包含很多条指令 因为有if-else.for这样的条件和循环存在,这些指令也不会一路平直执行下去. 一个计算机程序是怎么被分解成一条条指令来执行的呢 1 CP ...

  9. Android UI控件常用库汇总

    现在App的开发已经是非常成熟,涌现了一大批开源的工具.这些项目能够提高我们的搬砖效率.以下是一些在开发中比较常使用的控件和库. ListView WaveSwipeRefreshLayout 水滴效 ...

  10. 狄利克雷卷积&莫比乌斯反演证明

    狄利克雷卷积简介 卷积这名字听起来挺学究的,今天学了之后发现其实挺朴实hhh. 卷积: "(n)"表示到n的一个范围. 设\(f,g\)是两个数论函数(也就是说,以自然数集为定义域 ...