Codeforces Round #334 (Div. 2) C. Lieges of Legendre

题意:给你一个字符串,你可以使得一个连续的01串翻转过来,然后问你最长的01相隔的子序列(不连续)的长度为多少

解:答案一定是max(len+2,n),len为原来01串的最长长度

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=1e5+10;
char s[maxm];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%s",s);
        int len=1;
        for(int i=1;i<strlen(s);i++)
        {
            if(s[i]!=s[i-1])
                len++;
        }
        printf("%d\n",min(len+2,n));
    }
    return 0;
}

你可能感兴趣的:(Codeforces Round #334 (Div. 2) C. Lieges of Legendre)