Codeforces #505(div1+div2) C Plasticine zebra

题意:给你一段字符串,可以选择任意多的位置,每个位置会反转两边的字符串,问交错的字符串最长是多长?

思路:找规律,仔细分析样例1.假设位置为 1 2 3 4 5 6 7 8 9,反转之后会发现答案是7 8 9 1 2 3 4 5 6 ,其中答案串是7 8 9 1 2,所以可以把原字符串复制一份粘在原字符串后面,找最长的交错串即可。

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<bitset>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#define INF 0x3f3f3f3f
#define pii pair<int,int> 
#define LL long long
#define mk(a,b) make_pair(a,b)
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;
char s[200010];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	rep(i,n)s[i+n]=s[i];
	int tmp=1,ans=0;
	rep(i,2*n-1){
		if(s[i+1]!=s[i])
			tmp++;
		else{
			ans=max(ans,tmp);
			tmp=1;
		}
	}
	ans=max(ans,tmp);
	printf("%d\n",min(ans,n));
}

  

 

转载于:https://www.cnblogs.com/pkgunboat/p/9504244.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值