#include<iostream>
#include<cstring>
using namespace std;
int d[50005];
int f[50005];
int n;
int solve(int k)
{
memset(f,0,sizeof(f));
int res=0;
int sum=0;
int ans=0;
int i;
for(i=0;i+k<=n;i++)
{
if((sum+d[i])%2)
{
f[i]=1;
ans++;
}
sum+=f[i];
if(i-k+1>=0)
sum-=f[i-k+1];//这里忘了加1,错误找了好久
}
int j;
for(j=i;j<n;j++)
{
if((sum+d[j])%2)
{
return -1;
}
sum-=f[j-k+1];
}
return ans;
}
int main()
{
cin>>n;
int i,j;
char ch;
memset(d,0,sizeof(d));
for(i=0;i<n;i++)
{
cin>>ch;
if(ch=='B')
d[i]=1;
}
int ans=0x3f3f3f3f;
int tmp=0;
for(i=1;i<=n;i++)
{
int res = solve(i);
if(res==-1)
continue;
if(ans>res)
{
ans=res;
tmp=i;
}
}
cout<<tmp<<' '<<ans<<endl;
}
poj 3276 Face The Right Way 关灯问题
最新推荐文章于 2018-05-16 10:26:17 发布