mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-07-07 18:06:58 +08:00
Add FZOI Codes
This commit is contained in:
33
FZOI/「USACO1.1」Broken Necklace.cpp
Normal file
33
FZOI/「USACO1.1」Broken Necklace.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include<cstdio>
|
||||
#include<algorithm>
|
||||
#define N 355
|
||||
using namespace std;
|
||||
|
||||
char a;
|
||||
int b[N];
|
||||
int n, ans;
|
||||
|
||||
int solve(int p, int dir)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
for(int j = p + n; len < n; len ++ , j += dir)
|
||||
{
|
||||
if(b[p] && b[j%n] && b[j % n] != b[p]) break;
|
||||
if(!b[p]) p = j % n;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d ", &n);
|
||||
for(int i = 0; i < n; i ++ )
|
||||
{
|
||||
a = getchar();
|
||||
b[i] = a == 'b' ? 1 : a == 'r' ? 2 : 0;
|
||||
}
|
||||
for(int i = 0; i < n; i ++ ) ans = max(ans, solve(i, - 1) + solve(i + 1, 1));
|
||||
ans = min(ans, n);
|
||||
printf("%d\n", ans);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user