标签:
/*
ID: awsd1231
PROG: beads
LANG: C++
*/
#include<iostream>
#include<cstdio>
usingnamespace std;
char necklace[500][2]={0};
int num[500]={0};
int n;
void clearNec(){
for(int i =0; i != n; i++)
necklace[i][1]=0;
}
int sumRight(int x){
char a = necklace[x][0];
int t =0;
while(necklace[x+t][0]==‘w‘)
a = necklace[x+++t][0];
int count =0;
for(int i = x; i != n;++i)
if(!necklace[i][1]&&(a == necklace[i][0]|| necklace[i][0]==‘w‘))++count;
elsereturn count;
for(int i =0; i != x;++i)
if(!necklace[i][1]&&(a == necklace[i][0]|| necklace[i][0]==‘w‘))++count;
elsereturn count;
return count;
}
int sumLeft(int x){
char a;
if(x) a = necklace[x-1][0];
else a = necklace[n-1][0];
int t =0;
while(necklace[x-t][0]==‘w‘)
a = necklace[x-++t][0];
int count =0;
for(int i = x -1; i !=-1;--i)
if(a == necklace[i][0]|| necklace[i][0]==‘w‘){
++count;
necklace[i][1]=1;
}
elsereturn count;
for(int i = n -1; i != x -1;--i)
if(a == necklace[i][0]|| necklace[i][0]==‘w‘){
++count;
necklace[i][1]=1;
}
elsereturn count;
return count;
}
int maxSum(){
int max =0;
for(int i =0; i != n;++i)
if(max < num[i]) max = num[i];
return max;
}
int main(){
freopen("beads.in","r", stdin);
freopen("beads.out","w", stdout);
cin >> n;
for(int i =0; i != n;++i)
cin >> necklace[i][0];
for(int i =0; i != n;++i){
clearNec();
num[i]= sumLeft(i)+ sumRight(i);
}
cout << maxSum()<< endl;
return0;
}
标签:
原文地址:http://www.cnblogs.com/liangyongrui/p/4541851.html