[size=small]进入USACO要注册才可看题:[/size] [url]http://train.usaco.org/usacogate[/url]
[size=medium]题目:【已翻译】[url]http://www.wzoi.org/usaco/11%5C202.asp[/url]
[color=blue]SAMPLE INPUT (file beads.in)
29
wwwbbrwrbrbrrbrbrwrwwrbwrwrrb
SAMPLE OUTPUT (file beads.out)
11[/color]
又一水题……YY的算法//无法用语言表达啊
[img]http://dl.iteye.com/upload/attachment/494721/fbe1ccf6-29de-31d2-a7d6-e2d6e1e93213.gif[/img]
……感觉飞一般的繁琐!
虽然1次A……但是写代码时感觉很是不爽
[/size]
[size=medium]题目:【已翻译】[url]http://www.wzoi.org/usaco/11%5C202.asp[/url]
[color=blue]SAMPLE INPUT (file beads.in)
29
wwwbbrwrbrbrrbrbrwrwwrbwrwrrb
SAMPLE OUTPUT (file beads.out)
11[/color]
又一水题……YY的算法//无法用语言表达啊
[img]http://dl.iteye.com/upload/attachment/494721/fbe1ccf6-29de-31d2-a7d6-e2d6e1e93213.gif[/img]
……感觉飞一般的繁琐!
虽然1次A……但是写代码时感觉很是不爽
[/size]
/*
ID: 1006100071
PROG: beads
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <set>
//#include <map>
#include <queue>
#include <utility>
#include <iomanip>
#include <stack>
#include <list>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h>
using namespace std;
int main()
{
freopen ("beads.in", "r", stdin);
freopen ("beads.out", "w", stdout);
int i, len, maxs, start, change;
bool hash[30] = {0};
string s;
cin >> len >> s;
s = s + s; //实现首尾相接
maxs = 1, change = start = 0;
len <<= 1; //串长加倍
if (s[0] != 'w')
hash[s[0]-'a'] = true, change = 1;
for (i = 1; i < len; i++)
{
//cout << i << ' ' << change << ' ' << s[i]-'a' << endl;
if (s[i] != 'w' && !hash[s[i]-'a'])
memset (hash, false, sizeof(hash)), hash[s[i]-'a'] = true, change++;
if (change > 2 || i == len-1)
{
//cout << i - start << "-----------\n";
if (maxs < i - start)
maxs = i - start;
change = 0;
memset (hash, false, sizeof(hash));
i = start;
start++;
if (s[start] != 'w')
hash[s[start]-'a'] = true, change = 1;
}
}
if (maxs > len / 2) //最多取所给原来的串长
maxs = len / 2;
cout << maxs << endl;
return 0;
}