beads.cpp

来自「USACO chapter one.May hope it useful to 」· C++ 代码 · 共 44 行

CPP
44
字号
/*
ID: chenkai4
PROG: beads
LANG: C++
*/
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("beads.in");
ofstream out("beads.out");

int maxN=0,N;
char necklace[350];
#define max(A,B) (A>B?A:B)
int main()
{
	in>>N;
	in>>necklace;
	int thisL,thisR;char lastL,lastR,t;
	for(int a=1;a<N;a++)
	{
		thisL=thisR=0;lastL=lastR='w';
		while((necklace[thisL]=='w'||necklace[thisL]==lastL||lastL=='w')&&(thisL<N))
		{
			if(lastL=='w')
				lastL=necklace[thisL];
			thisL++;
		}
		while((necklace[N-thisR-1]=='w'||necklace[N-thisR-1]==lastR||lastR=='w')&&(thisR<N))
		{
			if(lastR=='w')
			lastR=necklace[N-thisR-1];
			thisR++;
		}
		if(thisL+thisR>=N){maxN=N;break;}
		maxN=max(maxN,thisL+thisR);
		t = necklace[N-1];
		for(int a=N-1;a>=1;a--)
			necklace[a]=necklace[a-1];
		necklace[0]=t;
	}
	out<<maxN<<endl;
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?