zoukankan      html  css  js  c++  java
  • 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
    ",min(ans,n));
    }
    

      

  • 相关阅读:
    Car HDU
    Defeat the Enemy UVALive
    Alice and Bob HDU
    Gone Fishing POJ
    Radar Installation POJ
    Supermarket POJ
    Moo Volume POJ
    Text Document Analysis CodeForces
    checkbox全选与反选

  • 原文地址:https://www.cnblogs.com/pkgunboat/p/9504244.html
Copyright © 2011-2022 走看看