2012/4/17

RE: [光通訊時代] Google Code Jam 2012 資格賽 第二題 Problem B. Dancing With the Googlers 重構跟短碼之後,可讀性?

在短一次 但是這次是錯的!!! 有空在review! 前進第四題!!!

 

#include "stdafx.h"

 

void main()

{

 

        int C[2][3] = {{1, 2, 2}, {0, 0, 1}};

        int l,n,s,p,i,j,t,x;

        scanf("%d", &l);

        for(i=0;i<l;i++)

        {

                int c=0;

                scanf("%d %d %d", &n, &s, &p);

                for(j=0;j<n;j++)

                {                                      

                    scanf("%d", &t);

                    int r = C[(x = p-t/3)-1][t-t/3*3];                                                 

                                        c +=  (x <= 0 || r%2 && s-->0 || r/2) && t && x <= 2;                   

                }

                printf("Case #%d: %d\n", i+1,c);

        }     

}

 

From: Kradark [mailto:kradark@gmail.com]
Sent: Tuesday, April 17, 2012 11:46 AM
To:
Subject: [
光通訊時代] Google Code Jam 2012 資格賽 第二題 Problem B. Dancing With the Googlers 重構跟短碼之後,可讀性?

 

重構跟短碼之後,可讀性?

#include "stdafx.h"

 

void main()

{

        int table[2][3] = {    {1, 2, 2}, {0, 0, 1} };

        int line,n,s,p,i,j,t,x; 

        scanf("%d", &line);

        for(i=0;i<line;i++)

        {

                int count=0;

                scanf("%d %d %d", &n, &s, &p);

                for(j=0;j<n;j++)

                {

                        scanf("%d", &t);

                        if(!(t || p)) count++;

                        if(!t) continue;

                        if( (x = p-t/3) > 2 ) continue;                  

                        if( x <= 0 ) { count++; continue; }                   

                        if( table[x-1][t-t/3*3] ==1 ) { count += s-->0;  continue; }

                        if( table[x-1][t-t/3*3] ==2 ) count ++;                    

                }

                printf("Case #%d: %d\n", i+1,count);

        }      

}

 

From:

 

Smail Set 一次 10分。

Large Set 一次 15分。

花費時間: 1hr 15min

 

http://code.google.com/codejam/contest/1460488/dashboard#s=p1&a=1

 

 

題目分析:

這一題在考題目理解能力,有人說數學的符號很重要,沒萊布尼茲發明微積分符號,

就沒有後來蓬勃的發展,那解程式符號與圖型也很重要,不然題目落落長,看了三遍也不懂。

 

看似很複雜,其實整體只有六種一般狀況加上一種例外。

六種一般狀況用表格表式,因為狀況單純所以用查表的,

就是table的第一與第二個column

 

 

 

From:

 

// DancingWithGooglers.cpp : Defines the entry point for the console application.

//

 

#include "stdafx.h"

 

void main()

{

        // 0=>x, 1=>sprz, 2=>count++

        int table[3][4] =

        {

                {0, 1, 0, 0},

                {0, 2, 0, 0},

                {0, 2, 1, 0}

        };

 

        int line,n,s,p,i,j,t,m,q,r,x;

        int count;

        scanf("%d", &line);

        for(i=0;i<line;i++)

        {

                count=0;

                scanf("%d %d %d", &n, &s, &p);

                for(j=0;j<n;j++)

                {

                        scanf("%d", &t);

                        if(t==0) //例外

                        {

                                if(p==0) count++;

                                continue;

                        }

                        m=t/3;

                        x = p-m;

                        if( x > 2 ) continue;

                        q = t-m*3;

 

                        //printf("n,s,p,t,m=t/3,x=p-m,q,table[q][x]=%d,%d,%d,%d,%d,%d,%d,%d\n",n,s,p,t,m,x,q,table[q][x]);

                        if(x>0)

                        {

                                r = table[q][x];

                                if(r==1) { //sprz

                                        if(s>0) {

                                                count ++;

                                                s--;

                                        }

                                }

                                if(r==2)

                                {

                                        count ++;

                                        //count += !(table[q][x]==0);

                                }

                        }else{

                                count++;                 

                        }

                }

                printf("Case #%d: %d\n", i+1,count);

        }      

}



--
Kradark 4/17/2012 11:45:00 上午 張貼在 光通訊時代

Google Code Jam 2012 資格賽 第二題 Problem B. Dancing With the Googlers 重構跟短碼之後,可讀性?

重構跟短碼之後,可讀性?

#include "stdafx.h"

 

void main()

{

        int table[2][3] = {    {1, 2, 2}, {0, 0, 1} };

        int line,n,s,p,i,j,t,x; 

        scanf("%d", &line);

        for(i=0;i<line;i++)

        {

                int count=0;

                scanf("%d %d %d", &n, &s, &p);

                for(j=0;j<n;j++)

                {

                        scanf("%d", &t);

                        if(!(t || p)) count++;

                        if(!t) continue;

                        if( (x = p-t/3) > 2 ) continue;                  

                        if( x <= 0 ) { count++; continue; }                   

                        if( table[x-1][t-t/3*3] ==1 ) { count += s-->0;  continue; }

                        if( table[x-1][t-t/3*3] ==2 ) count ++;                    

                }

                printf("Case #%d: %d\n", i+1,count);

        }      

}

 

From:

 

Smail Set 一次 10分。

Large Set 一次 15分。

花費時間: 1hr 15min

 

http://code.google.com/codejam/contest/1460488/dashboard#s=p1&a=1

 

 

題目分析:

這一題在考題目理解能力,有人說數學的符號很重要,沒萊布尼茲發明微積分符號,

就沒有後來蓬勃的發展,那解程式符號與圖型也很重要,不然題目落落長,看了三遍也不懂。

 

看似很複雜,其實整體只有六種一般狀況加上一種例外。

六種一般狀況用表格表式,因為狀況單純所以用查表的,

就是table的第一與第二個column

 

 

 

From:

 

// DancingWithGooglers.cpp : Defines the entry point for the console application.

//

 

#include "stdafx.h"

 

void main()

{

        // 0=>x, 1=>sprz, 2=>count++

        int table[3][4] =

        {

                {0, 1, 0, 0},

                {0, 2, 0, 0},

                {0, 2, 1, 0}

        };

 

        int line,n,s,p,i,j,t,m,q,r,x;

        int count;

        scanf("%d", &line);

        for(i=0;i<line;i++)

        {

                count=0;

                scanf("%d %d %d", &n, &s, &p);

                for(j=0;j<n;j++)

                {

                        scanf("%d", &t);

                        if(t==0) //例外

                        {

                                if(p==0) count++;

                                continue;

                        }

                        m=t/3;

                        x = p-m;

                        if( x > 2 ) continue;

                        q = t-m*3;

 

                        //printf("n,s,p,t,m=t/3,x=p-m,q,table[q][x]=%d,%d,%d,%d,%d,%d,%d,%d\n",n,s,p,t,m,x,q,table[q][x]);

                        if(x>0)

                        {

                                r = table[q][x];

                                if(r==1) { //sprz

                                        if(s>0) {

                                                count ++;

                                                s--;

                                        }

                                }

                                if(r==2)

                                {

                                        count ++;

                                        //count += !(table[q][x]==0);

                                }

                        }else{

                                count++;                 

                        }

                }

                printf("Case #%d: %d\n", i+1,count);

        }      

}

Google Code Jam 2012 資格賽 第二題 Problem B. Dancing With the Googlers

Smail Set 一次 10分。

Large Set 一次 15分。

花費時間: 1hr 15min

 

http://code.google.com/codejam/contest/1460488/dashboard#s=p1&a=1

 

 

題目分析:

這一題在考題目理解能力,有人說數學的符號很重要,沒萊布尼茲發明微積分符號,

就沒有後來蓬勃的發展,那解程式符號與圖型也很重要,不然題目落落長,看了三遍也不懂。

 

看似很複雜,其實整體只有六種一般狀況加上一種例外。

六種一般狀況用表格表式,因為狀況單純所以用查表的,

就是table的第一與第二個column

 

 

 

From:

 

// DancingWithGooglers.cpp : Defines the entry point for the console application.

//

 

#include "stdafx.h"

 

void main()

{

        // 0=>x, 1=>sprz, 2=>count++

        int table[3][4] =

        {

                {0, 1, 0, 0},

                {0, 2, 0, 0},

                {0, 2, 1, 0}

        };

 

        int line,n,s,p,i,j,t,m,q,r,x;

        int count;

        scanf("%d", &line);

        for(i=0;i<line;i++)

        {

                count=0;

                scanf("%d %d %d", &n, &s, &p);

                for(j=0;j<n;j++)

                {

                        scanf("%d", &t);

                        if(t==0) //例外

                        {

                                if(p==0) count++;

                                continue;

                        }

                        m=t/3;

                        x = p-m;

                        if( x > 2 ) continue;

                        q = t-m*3;

 

                        //printf("n,s,p,t,m=t/3,x=p-m,q,table[q][x]=%d,%d,%d,%d,%d,%d,%d,%d\n",n,s,p,t,m,x,q,table[q][x]);

                        if(x>0)

                        {

                                r = table[q][x];

                                if(r==1) { //sprz

                                        if(s>0) {

                                                count ++;

                                                s--;

                                        }

                                }

                                if(r==2)

                                {

                                        count ++;

                                        //count += !(table[q][x]==0);

                                }

                        }else{

                                count++;                 

                        }

                }

                printf("Case #%d: %d\n", i+1,count);

        }      

}

2012/4/16

補鈣800D(維他命D3+鈣)


Vitamin D3 800 I.U. Calcium Carbonate (
600mg

碳酸鈣)


Google Code Jam 2012 資格賽 第三題 Problem C. RecycledNumbers

Smail Set 一次 10分。

Large Set 兩次 0分。

 

// RecycledNumbers.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include "string.h"

 

void main()

{     

        int line, len, i, n, k, x, A, B, m, head, tail, pow, pow2, ans, cnt, dup;      

        char str[8];

 

        scanf("%d\n\r", &line);   

        for(i=0;i<line;i++) {         

                scanf("%d %d", &A, &B);              

                ans=0;             

                for(n=A;n<=B;n++)

                {     

                        //printf("%d => ", n);

                        sprintf(str,"%d",n);

                        len = strlen(str);                       

                        tail = n;

                        pow = 1;

                        pow2 = 1;

                        for(x = 0; x<len; x++) {

                                pow2 *= 10;

                        }     

                        cnt = 0;

                        dup = 1;

                        if( len == 4 && (n%100 == n/100) ) {

                                dup=2;

                        }

                        if( len == 6 && (n%1000 == n/1000) ) {

                                dup=2;

                        }

                        if( len == 6 && (n%100 == (n/100)%100) && (n%100 == (n/10000))) {

                                dup=3;

                        }

                        for(k=1;k<len;k++) {

                                tail /= 10;

                                pow *= 10;                             

                                pow2 /= 10;

                                head = (n % pow)*pow2;

                                m = head + tail;

                                if( A<=n && n<m && m<=B ) {

                                        //printf("%d ",m);

                                        cnt++;

                                }                                     

                        }     

                        ans += cnt/dup;

                        //printf("\n");

                }

                printf("Case #%d: ", i+1);

                printf("%d\n", ans);

        }             

}