CPE檢定考

所有的程式碼都蒐集在這裡:
https://github.com/alice90270/NTHU_CPE

這半年來的考試趨向已經不像文義那時候簡單了
不太考括號題,反而出現一堆BFS,DFS,tree的題目
同一次考試會有極簡單跟級難的題目
例如這次考

  • GCD & LCM這種智障題
  • Can you escape這種雞巴題
    我實在想不到為何難度差異這麼大只好背了

Alice小筆記

  1. TLE
    因為strlen()作一次很花時間,放在for裡面會跑很多次
    解決方式:把strlen拉到迴圈以外
    length=strlen(inputString);
    for(i=0;i<length;i++)

  2. Runtime Error
    陣列要開夠大,大概array[10^6]就是極限了
    這時候就需要malloc

  3. n筆測資輸入
    while(scanf("%d",&n)!=EOF){
    while(n){
    //程式執行n次
    }

  4. 第一個輸入後加 %c 來處理 "\n"
    scanf("%d%c", &testcase, &sp);
    或第二個輸入前加空白(忽略所有換行跟空白)
    scanf(" %c", &input)
    不然"\n"會被之後的輸入吃進去

  • Move
  • Mouse Maze
  • Parentheses Matching
  1. 處理含空白以及換行輸入
    gets(string)

  2. EOF結尾
    while(gets())
    while(scanf()!=EOF)

  3. int 改用long long int大的測資比較不會有錯

  4. presentation error
    每一行的最後面(換行前)輸出不能有空白

  5. scanf("%s") 遇到空白會吃不進來
    改用gets()

  6. Sort

qsort(array, strlen(array), sizeof(int), cmp);

int cmp(const void *a, const void *b)
    return *(int*)a- *(int*)b;
  1. Malloc 要開超大陣列卻Runtime error的時候
char *buf;
buf = (char*)malloc(sizeof(char)*len*pow(2,times));

  1. struct

有兩種寫法,意義一樣

// 1
typedef struct{
    int name[40];
    int score;
}variable;

// 2
struct variable{
    int name[40];
    int score;
};

重要刷題

@重複率高@
@10576 - Move

typedef struct cc{
    int front;
    int next;
}node;
node *list;
list = (node*)malloc(sizeof(node)*(n+1));

list[3].front;

@10683 - Look and Say
@%10860 - Queueing

f ,p
POP
OUT
PUSH

@%10953 - Simply Fractions
@*11086 - K Characters
@11094 - Binary Addition
@*11140 - Parentheses Matching
@*11142 - Matrix Multiplication
@11271 - Count the Leaves
@*11274 - GCD and LCM

long long int gcd(long long int a , long long int b){
    if (a%b==0)
        return b;
    else
        return gcd(b, a%b);
}

@11221 - Mouse Maze

近期考古
*9081 - Counting Sort
*11053 - Lexicographic Order
*11173 - Adding Decimals
*11215 - Maximum Frequency
*11217 - Encryption
*11272 - K Characters
*11425 - Carry In
*11434 - Count the Value

%10275 - Perfect Shuffle
%10276 - Can a Permutation Be Sorted By a Stack
10479 - Islands
10748 - Trick or Treat
10801 - Fill the Boxes
10802 - Minimum Spanning Tree
10805 - Thousands Separator
10824 - hanoi
10862 - Calendar
10951 - Inversion Pair
10985 - Column Sum and Row Sum
10988 - Stable Sort
11005 - Lagrange's Four-Square Theorem
11055 - Vector Intersection
11091 - Suffix Prefix
11143 - Tree
11276 - Subset Sum
11281 - Set Intersection

資訊之芽

http://tw-csie-sprout.github.io/c2016/#!slides.md

育輝精選

http://codepad.org/U5W0XdvC
MST code
http://acm.cs.nthu.edu.tw/problem/10803/
stable sort
http://codepad.org/KYLYzvcI
http://codepad.org/AuPzAVLD
http://140.114.86.238/problem/9104/
這題也出過
http://140.114.86.238/problem/10861/
http://codepad.org/igeOgT7F
誇湖這題也很重要
http://140.114.86.238/problem/10862/
日曆
http://codepad.org/FCyZkVvx

考古題

105學年度
105學年下學期第一次程式檢定
Parentheses Matching
http://codepad.org/0FQclN9N
要用stack

11141 - Maximum Frequency
http://codepad.org/9ZnluCFS

11142 - Matrix Multiplication
http://codepad.org/voSpzG6i
輸出注意不能有空白在換行之前

文義衝刺班精選

103~105出題達5次以上 出題頻率極高:

10682 - Parentheses Matching
http://acm.cs.nthu.edu.tw/problem/10682/

11086 - K Characters
http://acm.cs.nthu.edu.tw/problem/11086/

11217 - Encryption
http://acm.cs.nthu.edu.tw/problem/11217/

11281 - Set Intersection
http://acm.cs.nthu.edu.tw/problem/11281/

11291 - Mouse Maze
http://acm.cs.nthu.edu.tw/problem/11291/

11343 - Simply Fractions
http://acm.cs.nthu.edu.tw/problem/11343/

11089 - Suffix Prefix
http://acm.cs.nthu.edu.tw/problem/11089/

根據以往經驗,第二次出題會跟第一次重複2~3題
因此要把第一次出題之題目練習過,通過機率會大幅提升
http://acm.cs.nthu.edu.tw/contest/1144/