• USACO Broken Necklace 通过了


    终于通过了,呵呵:

    /*
    ID: qq104801
    LANG: C
    TASK: beads
    */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    /* for debug only:counter
    */
    void debug_dummy(void)
    {
        return;
    }
    
    int n;
    char k[800];
    
    int count()
    {
        int i;
        int a,b,w;
        int m;
        char c;    
        memcpy(k+n,k,n);
        //printf("%s
    ",k);
    
        a=0;
        b=0;
        w=0;   
        i=0;
        m=0;
        c='0';
        while(i < (2*n))
        {        
            if(k[i]=='w')
            {
                b++;
                w++;            
            }
            else if(k[i]==c)
            {
                b++;
                w=0;            
            }
            else
            {
                if(m<(a+b))
                    m=a+b;              
                a=b-w;
                b=w+1;  
                w=0;
                c=k[i];                              
            }
            //printf("%2d  %c %d %d
    ",i,k[i%n],a,b);
            if(m<(a+b))
                m=a+b;
            //printf("%c-%3d-i:%2d   a:%2d   b:%2d   w:%2d
    ",k[i],i,i%n,a,b,w);
            i++;        
        }
    
        if(m>n)
            m=n;
        //printf("m:%d
    ",m);
        return m;
    }
    
    
    main () {    
        FILE *fin = fopen ("beads.in", "r");
        FILE *fout = fopen ("beads.out", "w");   
        
        fscanf(fin,"%d",&n);
        fscanf(fin,"%s",k);  
        //printf("n:%d
    ",n);
        //printf("k:%s
    ",k); 
    
        fprintf(fout,"%d
    ",count());
        fclose(fin);
        fclose(fout);
        exit (0);
    }

    结果:

    USER: ll tom [qq104801]
    TASK: beads
    LANG: C
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.003 secs, 2164 KB]
       Test 2: TEST OK [0.005 secs, 2164 KB]
       Test 3: TEST OK [0.003 secs, 2164 KB]
       Test 4: TEST OK [0.005 secs, 2164 KB]
       Test 5: TEST OK [0.008 secs, 2164 KB]
       Test 6: TEST OK [0.003 secs, 2164 KB]
       Test 7: TEST OK [0.005 secs, 2164 KB]
       Test 8: TEST OK [0.005 secs, 2164 KB]
       Test 9: TEST OK [0.003 secs, 2164 KB]
    
    All tests OK.
    
    Your program ('beads') produced all correct answers! This is your submission #7 for this problem. Congratulations!
    
    Here are the test data inputs:
    
    ------- test 1 ----
    29
    wwwbbrwrbrbrrbrbrwrwwrbwrwrrb
    ------- test 2 ----
    3
    rrr
    ------- test 3 ----
    77
    rwrwrwrwrwrwrwrwrwrwrwrwbwrwbwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwr
    ------- test 4 ----
    17
    wwwwwwwwwwwwwwwww
    ------- test 5 ----
    50
    bbrrrbrrrrrrrrbrbbbrbrrbrrrrbbbrbrbbbbbrbrrrbbrbbb
    ------- test 6 ----
    8
    rrwwwwbb
    ------- test 7 ----
    200
    rrrrrrrrrrrrrrrrrrrrbbbbbbbbbbbbbbbbbbbbrrrrrrrrrrrrrrrrrrrrbbbbbbbbbbbbbbbbbbbbrrrrrrrrrrrrrrrrrrrrbbbbbbbbbbbbbbbbbbbbrrrrrrrrrrrrrrrrrrrrbbbbbbbbbbbbbbbbbbbbrrrrrrrrrrrrrrrrrrrrbbbbbbbbbbbbbbbbbbbb
    ------- test 8 ----
    350
    rrbbrbbbwbwwbwbbbbwwrrbbwbrwbrwbbbrbrwrwbrwwwrrbbrrwrbbrwbwrwwwrbrwwwwwrwbwwwrrbrrbbbrbrbbbrbbbrbbwbbbbbrbrrbrwwbrrrrwbwrwrbbwbwrbrbrwwbrrbwbrwwbwwwbrbwrwbwbrbbbwrbwwrrrbwbwbbbbbrrwwwrbrwwrbbwrbbrbbrbwrrwwbrrrbrwbrwwrbwbwrrrbwrwrrbrbbwrwrbrwwwrwbwrrwwwwrrrwrrwbbwrwwrwrbwwbwrrrrbbwrbbrbwwwwwbrbbrbbrbrwbbwbwwbbbbbwwwrbwwbbbwrwwbbrrwrwbwrrwwwrrrwrrwww
    ------- test 9 ----
    333
    rwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwb
    
    Keep up the good work!
    Thanks for your submission!

    呵呵,中途回老家呆了几天,以至于现在才通过。

    /***********************************************

    看书看原版,原汁原味。

    不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

    没有原书,也要网上找PDF来看。

    网上的原版资料多了去了,下载东西也到原始下载点去看看。

    你会知其所以然,呵呵。

    ***********************************************/

  • 相关阅读:
    Atitit 编程语言原理与概论attilax总结
    Atitit.attilax软件研发与项目管理之道
    Atitit.研发团队与公司绩效管理的原理概论的attilax总结
    Atitit.软件兼容性原理与实践 v3 q326.docx
    Atitit.html css  浏览器原理理论概论导论attilax总结
    atitit.http原理与概论attilax总结
    Atitit.并发编程原理与概论 attilax总结
    Atitit selenium3 新特性
    asp.net里获取当前时间,并字符串格式化转换(转)
    软件设计师
  • 原文地址:https://www.cnblogs.com/dpblue/p/3940103.html
Copyright © 2020-2023  润新知