题解:
贪心
枚举k
然后判断一下是否可行
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=;
int n,a[N],b[N],sum,c[N];
char ch[];
int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++)
{
scanf("%s",&ch);
if (ch[]=='B')a[i]=; else a[i]=;
}
int ans=n,pos;
for (int i=;i<=n;i++)
{
int flag=,zs=sum=;
for (int j=;j<=n;j++){b[j]=a[j]; c[j]=;}
for (int j=;j+i-<=n;j++)
{
sum^=c[j];
if (b[j]^sum){sum^=; c[j+i]=; zs++;}
}
for (int j=n-i+;j<=n;j++)
{
sum^=c[j];
if (b[j]^sum)
{
flag=;
break;
}
}
if (!flag&&zs<ans)
{
ans=zs;
pos=i;
}
}
printf("%d %d",pos,ans);
}