竹北資研競程教材 === ## 小技巧 ```cpp #include<bits/stdc++.h> //在GNU環境下加入此標頭檔,相當於include所有library。 int main(){ std::ios::sync_with_stdio(0); std::cin.tie(0);//在main中加入這兩行能讓IO變快,但加了後就只能使用cin和cout。 //使用endl,IO會變慢。 cout<<"Hello World!!"<<endl; //bad (╬☉д⊙) cout<<"Hello World!!"<<'\n'; //good (^_^) } ``` ## 時間複雜度 [入門版](https://jason-chen-1992.weebly.com/home/time-space-complexity) [進階版](https://alrightchiu.github.io/SecondRound/complexityasymptotic-notationjian-jin-fu-hao.html) ## 基礎資料結構 ### Stack(堆疊) ![image alt](https://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Data_stack.svg/1280px-Data_stack.svg.png) 可以把堆疊想成是一疊盤子,只能從頂部放入或取走盤子,且越晚放到盤子堆上的會優先被拿走,這就是Stack的特性,叫做***LIFO(Last In Fitst Out)***。Stack有push(在頂部加入資料)和pop(從頂部取出資料)兩種基本操作。 #### [Stack in C++ STL](https://www.cplusplus.com/reference/stack/stack/) ##### 基本method 1. st.pop() : O(1) 彈出 2. st.push() : O(1) 壓入 3. st.top() : O(1) 讀取頂部資料,要注意使用此method時stack必須不為空 4. st.size() : O(n) 查看stack內元素量