您的位置:首页 > 其它

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

2015-12-02 17:05 351 查看
题意:给你一个字符串,你可以使得一个连续的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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: