【枚举】Broken Necklace
生活随笔
收集整理的這篇文章主要介紹了
【枚举】Broken Necklace
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
首先一定要先把題意讀懂,讀題時一定要專注仔細(xì)。題目讀懂后還是思考,思考好了,條理清晰了,才可以開始碼代碼。
?
因為是環(huán)所以mencpy(s + n, s, n);然后,?用a表示前一段的連續(xù)長度, b表示當(dāng)前段的連續(xù)長度, w表示在當(dāng)前出現(xiàn)的w的連續(xù)數(shù)目.
然后還有一個需要注意的就是,如果全是一樣的bead,為了防止結(jié)果超過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; } /**/?
總結(jié)
以上是生活随笔為你收集整理的【枚举】Broken Necklace的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微分几何笔记(1):概念与定义
- 下一篇: 主动降噪耳机排行榜10强,主动降噪耳机十