首页 > 代码库 > USACO Broken Necklace 通过了

USACO Broken Necklace 通过了

终于通过了,呵呵:

/*ID: qq104801LANG: CTASK: 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: beadsLANG: CCompiling...Compile: OKExecuting...   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 ----29wwwbbrwrbrbrrbrbrwrwwrbwrwrrb------- test 2 ----3rrr------- test 3 ----77rwrwrwrwrwrwrwrwrwrwrwrw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rwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbKeep up the good work!Thanks for your submission!

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

USACO Broken Necklace 通过了