【枚举】Broken Necklace

首先一定要先把题意读懂,读题时一定要专注仔细。题目读懂后还是思考,思考好了,条理清晰了,才可以开始码代码。

 

因为是环所以mencpy(s + n, s, n);然后, 用a表示前一段的连续长度, b表示当前段的连续长度, w表示在当前出现的w的连续数目.

然后还有一个需要注意的就是,如果全是一样的bead,为了防止结果超过n,我们直接min(n, res);就好了。

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
char s[700 + 24];
char c = '0';
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n, m, res = 0, a = 0, b = 0, w = 0;	
	scanf("%d", &n);
	m = n << 1;
	getchar();
	scanf("%s", s);
	memcpy(s + n, s, n);
	for(int i = 0; i < m; i++) {
		if(s[i] == 'w')	{b++; w++;}
		else if(s[i] == c)	{b++; w = 0;}
		else	{
			res = max(res, a + b); 
			a = b - w; b = w + 1; 
			w = 0; c = s[i];
		}
	}
	res = max(res, a + b);
	printf("%d\n", min(res, n));
	return 0;
}
/**/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值