zoukankan      html  css  js  c++  java
  • usaco Section1.1 Broken Necklace

    题目链接:http://cerberus.delos.com:790/usacoprob2?a=75WI6aQtaO2&S=beads

    1Y这道题目没什么,就是情况多一点,麻烦一点=_=

     1 /*
     2 ID: zypz4571
     3 LANG: C++
     4 TASK: beads
     5  */
     6 
     7 #include <cstdio>
     8 #include <cstdlib>
     9 #include <cstring>
    10 #include <cmath>
    11 #include <cctype>
    12 #include <algorithm>
    13 #include <queue>
    14 #include <set>
    15 #include <queue>
    16 #include <list>
    17 #include <map>
    18 #define INF 0x3f3f3f3f
    19 #define mid int m=(l+r)/2
    20 using namespace std;
    21 int main ( int argc, char *argv[] )
    22 {
    23     freopen("beads.in", "r", stdin); 
    24     freopen("beads.out", "w", stdout);
    25     char a[360]; int n; bool b[360]; memset(b, false, sizeof(b));
    26     scanf("%d", &n);scanf("%s",a);
    27     int cnt = 0, i, j, k, Max = 0;
    28     for ( i= 0; i< n; ++i ) {
    29         cnt = 0;
    30         memset(b, false, sizeof(b));
    31         j = i; if (a[j] == 'w') while (a[j] == 'w' && !b[j]) {
    32             b[j] = true, cnt++, ++j; if (j > n-1) j = j % n;
    33         }
    34         char fir = a[j]; while ((a[j] == fir || a[j] == 'w') && !b[j]) {
    35             b[j] = true, cnt++, ++j; if (j > n-1) j %= n;
    36         }
    37         k = i-1; if (k < 0) k = (k+n)%n; if (a[k] == 'w') while (a[k] == 'w' && !b[k]) {
    38             b[k] = true, cnt++, --k; if (k < 0) k = (k+n)%n;
    39         }
    40         char sec = a[k]; while ((a[k] == sec || a[k] == 'w') && !b[k]) {
    41             b[k] = true, cnt++, --k; if (k < 0) k = (k+n)%n;
    42         }
    43         if (cnt > Max) Max = cnt;
    44     }
    45     printf("%d
    ", Max);
    46 
    47         return EXIT_SUCCESS;
    48 }                /* ----------  end of function main  ---------- */

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

  • 相关阅读:
    eclipse中统计代码行数
    vmware ubuntu 最近遇到的一些问题
    Shows how to create and run composites dynamically
    程序员的艺术:排序算法舞蹈
    Apache Mina 网络通信
    OutOfMemoryError汇总
    c++/java/c# 几种编程语言的指针、引用比较
    Silverlight开发工具集合
    web.cong 详解
    ASP.NET中的web.config配置
  • 原文地址:https://www.cnblogs.com/liuxueyang/p/3189238.html
Copyright © 2011-2022 走看看