码迷,mamicode.com
首页 > 其他好文 > 详细

USACO Broken Necklace 通过了

时间:2014-08-27 20:12:48      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   for   ar   div   log   

终于通过了,呵呵:

/*
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\n",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\n",i,k[i%n],a,b);
        if(m<(a+b))
            m=a+b;
        //printf("%c-%3d-i:%2d   a:%2d   b:%2d   w:%2d\n",k[i],i,i%n,a,b,w);
        i++;        
    }

    if(m>n)
        m=n;
    //printf("m:%d\n",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",n);
    //printf("k:%s\n",k); 

    fprintf(fout,"%d\n",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!

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

USACO Broken Necklace 通过了

标签:style   blog   color   os   io   for   ar   div   log   

原文地址:http://www.cnblogs.com/dpblue/p/3940103.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!