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);

        }             

}

Google Code Jam 2012 資格賽 第一題 Problem A. Speaking in Tongues

#include "stdafx.h"
#include "string.h"

int main(int argc, char* argv[])
{
char map[] = "yhesocvxduiglbkrztnwjpfmaq";
int line, i;
char c;

scanf("%d\n\r", &line);
for(i=0;i<line;i++) {
printf("Case #%d: ", i+1);
while(scanf("%c",&c) == 1 && c != '\n')
{
printf("%c",c==' '?' ':map[c-'a']);
}
printf("\n");
}
return 0;
}

2012/4/11

MOD已經擺脫過去負面形像了!

中時電子報:媒體收視滿意度MOD追上  http://news.chinatimes.com/tech/11050904/122012041000382.html

可見MOD已經擺脫過去負面形像了!

目前由於新、舊平台轉換青黃不接,新、舊平台服務差異:新平台目前暫未提供VOD18+、歡唱坊(無麥克風插孔)、金融理財(無金融卡插槽) 服務及台互、靖天SVOD服務,預計5月份可陸續推出服務。

spring

Rem ==========以下是按鍵精靈錄製的內容==========
MoveTo 727,409
LeftClick 1
Delay 5875
LeftClick 1
MoveTo 902,619
Delay 5172
LeftClick 1
MoveTo 817,575
Delay 3093
LeftClick 1
MoveTo 717,419
Delay 11965
LeftClick 1
Delay 6172
LeftDown 1
LeftClick 1
LeftUp 1
Rem ==========以上是按鍵精靈錄製的內容==========

2012/4/3

100-DB

若某企業資料庫中紀錄員工資料的關聯式(relational)資料表(table)之schema 如下:
Employee (EmpNum, Name, Salary, SupNum)

各屬性(attribute)之意義依序為員工代碼、姓名、月薪、直屬長官員工代號,其中
EmpNum 為主鍵(PK);

SupNum 為外來鍵(FK),參照到Employee 的EmpNum。請寫一SQL 命令,查出每一位月薪在
50,000 元以上的員工(有管轄員工者)所直接管轄的員工,查詢結果包括上司姓名及下\
屬姓名,且必
須依上司姓名順序再依下屬姓名順序排列。【10 分】

SELECT E1.Name AS 上司姓名 , E2.Name AS 下屬姓名
FROM Employee AS E1 , Employee AS E2
WHERE E1.EmpNum = E2.SupNum AND E1.Salary > 50000
ORDER BY 上司姓名 , 下屬姓名

指標就是無正負號整數變數

void f(int *p, int a[]){p=a;}
void main()
{
int a[]={1,3,5,7};
int *p=&a[1];
f(p,a);
p++;
printf("%d",*(p));
}


嚴格說起來,C只提供call by value,
因為指標就是整數變數,
16位元的指標是16位元的整數變數,
32位元的指標是32位元的整數變數,
64位元的指標是64位元的整數變數,
傳指標只是傳一個整數過去而已,嚴格說起來,也只是call by value。
所以把p傳到f(int *p, int a[])中,只是把一個位址(value)傳到f()裡,f()裡是把p的值指向a,
但無論如何,回到main()時,main()中p這個指標變數(無正負號整數變數)就變回原來main()中&a[1]的位址,也就所以,p++後,p就指向&a[2]的位置。

以上只是我個人的一種想法而已,不代表教科書立場。



ANS:5

2012/4/2

101年從業人員(基層專員)遴選

http://botexam.tabf.org.tw/tw/ptc_101cht/BotAns01uoprthqpgn.asp

100 年

1. 工務類專業職(四)第一類專員 - 類組代碼:96101 - 最低錄取分數:72.23

2. 工務類專業職(四)第一類專員 - 類組代碼:96201 - 最低錄取分數:69.45

3. 工務類專業職(四)第一類專員 - 類組代碼:96301 - 最低錄取分數:76.11

4. 工務類專業職(四)第一類專員 - 類組代碼:96401 - 最低錄取分數:70.55

5. 工務類專業職(四)第一類專員 - 類組代碼:96501 - 最低錄取分數:75.46

6. 資訊類專業職(四)第一類專員 - 類組代碼:96601 - 最低錄取分數:77.11

7. 資訊類專業職(四)第一類專員 - 類組代碼:96701 - 最低錄取分數:75.24

8. 業務類專業職(四)第一類專員 - 類組代碼:96801 - 最低錄取分數:82.38

2012/3/29

消基會抨擊,根本是無感降價,以ADSL為例,每個月省14元

目前全台已經有超過2800萬人次的手機及上網用戶,為了回應民眾覺得行動電話費率太
貴的呼聲,NCC從前年開始要求業者連續3年調降,今年公布的降幅只有3.58%,比去年
的4.04%來的低,4月1日起適用;不過消基會抨擊,根本是無感降價,以ADSL為例,每
個月省14元,1年最多省168元,根本是無感降價。
在台灣走到哪,似乎都能看到民眾人手一機,不斷講電話,台灣手機普及率之高可見一
斑,但通話費率也被民眾抱怨太高,而NCC在28日公布最新的行動電話費率調降案,五
大電信業者降幅大約在3.58%至4.84%,其中威寶降幅最大,台灣大最少。
另外月租資費方案所包含的通話分鐘數也增加了,以中華電信為例,大家講989型月
租,原本網內外語音送251分鐘,將多10分鐘,打給網外朋友每分鐘2.706至9.042元,
現在降為2.604到8.718元。
而ADSL電路費降幅約3.396%,換算後月租型約降了5到14元,新費率4月1日起適用,2項
降價預估共有2800萬用戶受惠。
但聽到新的調降費率,消基會批評根本是「無感」價降,以ADSL為例,每個月省14元,
1年最多省168元,實在太少沒誠意,業者則說降價幅度有成本考量,希望消費者理解。

wireshark就是早期的ethereal

wireshark就是早期的ethereal,嚴格說起來wireshark是ethereal後繼者。雖然在使用
這介面上看不太出來有什麼特別不同的,但是在內涵上已經大異其趣。
wireshark相對於左邊的Sniffer Pro具有以下的優點:

1. 開放原始碼
2. 完全免費
3. 支援通訊協定
12分鐘前
我會這麼說都是因為他是開放原始碼軟體,當然這代表著這一套是完全免費的軟體,而
且有許多程式設計師可以貢獻自己的原始碼,能夠很快地因應推陳出新的通訊協定,提
供最新最完整的剖析器。

像當初我們在研究MPEG2 Transport Stream的Header時,購買了Sniffer Pro,但當時
的Sniffer Pro注重於商業報表,也就是那是一套給老闆看得網路協定分析器,
但不是給工程師看得,我就轉向找尋開放原始碼的支援,假若沒有支援,甚至於我可以
自己撰寫再編譯。所幸再找到當時的ethereal時,
居然已經對於MPEG2 Transport Stream有完整支援,可以解析PID等表頭資訊。
11分鐘前
最後再補充本軟體其他的強大功能,支援線上抓取或者離線,流量統計,簡單的報表分
析等等。
多平台支援,Windows, Linux, OS X, Solaris, FreeBSD, NetBSD等等。
除了GUI模式外,也支援文字命令模式方便排程執行。
可以輸出成多種格式包含XML, PostScriptR, CSV,純文字檔等等。

2012/3/28

Crystal Report

According my exprience about creating dozens of crystal reports,
I determined to give Crystal Report a positive opinion. It has several
features:

Subreport: its meaning is that you can include a smaller report in a bigger
report. The two report could read it own data from different tables or even
different database.

Compatitble with .net framework: You can easily combine a report in your web
applications with the same syntax.

User friendly: Through serveral generations, the user interface is developed
more friendly. A experienced developer could create a basic report in ten
minutes. The section of header, footer and repeated parts meet the need of
most bosses and customers.

Huge Database Engine Supported: Most famous database platform including
Microsoft SQL Server, Oracle DB, IBM informix, Mysql and other database with
ODBC Driver.

根據我創建幾十個水晶報表的過往經驗,我決定給水晶報表了正面的評分,它有幾個特
點:

子報表:它的意思是,你可以在一個更大的報告包括數個小報告,各個報告可以從不同
的表格讀取它自己的數據,甚至由不同的資料庫。
與net框架相容:你可以很容易地在您的Web應用程序與之結合起來,且可以使用.net
同的語法,如C#、VB.net。

友善的圖型使用者界面:經過十餘代的演進,好的一個經驗豐富的開發人員可以在十幾
分鐘內創建一個基本的報表,報表頁首,頁腳和資料部份的分割方式,可以滿足大多數
老闆和客戶的需要。

龐大的數據庫引擎所支持:最有名的包括微軟SQL Server,Oracle資料庫,IBM的
Informix,MySQL和其他資料庫提供ODBC Driver的資料庫平台。也支援ADO.net。

提供Script Language: 許多由SQL不容易撰寫的演算式,或者因為不想修改預存程序而
影響已經正常運作的報表時,經由報表引擎所提供的Script Language,就非常的恰
當。

提供豐富的圖表功能: 雜亂的龐大數據,常令人眼花撩亂,Crystal Report可以在報表
中依資料展現高可讀性的圖表,如:條形圖、折線圖、面積圖、餅圖、干特圖等等。讓
老闆和客戶可以一目瞭然。

可以匯出多種不同的格式:包括XML、PDF、HTML、和Microsoft Excel。且相容性極
佳,除了讓終端使用者可以進行後製,重製。也提供歷史性報表最終的儲存方式。

中華電信董事會決議通過100年度盈餘分配案

中華電信(2412)(27)日董事會決議通過100年度盈餘分配案,每股分配現金股利新台幣5.4608元,計分配股東現金股利4236,1864,093元。

 

2012/3/21

Ghost這個軟體勾起我在計算機中心打工的經驗

Ghost這個軟體勾起我在計算機中心打工的經驗,
記得當時有三間PC教室,電腦有50至100部電腦不等,
維護電腦一直是我們工讀生的夢靨,
但自從用了Ghost,一切變得輕鬆自在。
當時pc教室的主機是windows 2000 workstation,支援ntfs,想必支援Windows 7跟XP
都不是問題。
Linux如果File System支援也沒多大問題。
這邊指的不是一台一台還原,
灌完OS後,再計算機中心的軟體不少,現在的image都不一小,
一台一台還原,可能要請10個工讀生吧。

答案就是Multicast,當時不懂什麼叫做Multicast,反正知道很快就對了,
18小時前
Ghost中Multicast的功能可能很多人看過,或是知道是用網路送出image。
除了有主機跟使用網路的方便性之外,
Multicast(群播)跟broadcast(廣播)不一樣,
broadcast會有許多份封包,一次ghost 100台pc會送出100份封包,
這樣switch可能也快不到哪裡去。
因為每一台pc收到的image理應是相同的,所以送出同一份封包即可,
這時候Multicast的特性就很有用,switch也不會那麼忙。
就這樣只要用還原一台電腦的時間,就搞定PC教室中所有的電腦。