usaco Section1.1 Broken Necklace

July 14, 2013
USACO

题目链接:http://cerberus.delos.com:790/usacoprob2?a=75WI6aQtaO2&S=beads 1Y这道题目没什么,就是情况多一点,麻烦一点=_=


/*
ID: zypz4571
LANG: C++
TASK: beads
 */

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <set>
#include <queue>
#include <list>
#include <map>
#define INF 0x3f3f3f3f
#define mid int m=(l+r)/2
using namespace std;
int main ( int argc, char *argv[] )
{
    freopen("beads.in", "r", stdin); 
    freopen("beads.out", "w", stdout);
    char a[360]; int n; bool b[360]; memset(b, false, sizeof(b));
    scanf("%d", &n);scanf("%s",a);
    int cnt = 0, i, j, k, Max = 0;
    for ( i= 0; i< n; ++i ) {
        cnt = 0;
        memset(b, false, sizeof(b));
        j = i; if (a[j] == 'w') while (a[j] == 'w' && !b[j]) {
            b[j] = true, cnt++, ++j; if (j > n-1) j = j % n;
        }
        char fir = a[j]; while ((a[j] == fir || a[j] == 'w') && !b[j]) {
            b[j] = true, cnt++, ++j; if (j > n-1) j %= n;
        }
        k = i-1; if (k < 0) k = (k+n)%n; if (a[k] == 'w') while (a[k] == 'w' && !b[k]) {
            b[k] = true, cnt++, --k; if (k < 0) k = (k+n)%n;
        }
        char sec = a[k]; while ((a[k] == sec || a[k] == 'w') && !b[k]) {
            b[k] = true, cnt++, --k; if (k < 0) k = (k+n)%n;
        }
        if (cnt > Max) Max = cnt;
    }
    printf("%d\n", Max);

        return EXIT_SUCCESS;
}                /* ----------  end of function main  ---------- */

vim插件超爽………^^前面的东西和注释,还有main函数,都是自己预先设定好的,其实还有很多东西,比如for, while, if, else, 甚至头文件,预处理,这些东西都有快捷键插入模板的~爽到爆==  

comments powered by Disqus