or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
C++ 基礎III
複習
for
while
用法如下:
很多條件 (continue/break)
離開當前的迴圈?
以下錯誤寫法
正確寫法
題目的各種輸入方式
t筆輸入
輸入直到讀到某個值
例如讀到 -1 為止
輸入直到 EOF
EOF = end of file
輸出 n 個數字用空白隔開
要求: 尾巴不能有空白
陣列宣告
使用
多維陣列
陣列是可以有多個維度的,例如:
注意事項
string
酷酷的標頭檔 (懶人)
包含
輸入輸出優化
檢定不會用到,但我提一下
請注意: 不要使用 endl 會導致使用 flush 而無法加快,請使用 '\n'
檢討題目
HB01
https://ncuma-oj.math.ncu.edu.tw/problem/HB01
純字串寫法
用位元運算
HB02
https://ncuma-oj.math.ncu.edu.tw/problem/HB02
HB03
https://ncuma-oj.math.ncu.edu.tw/problem/HB03
前綴和
(Partial sum)
Partial sum 數列前 k 項和。
給定一個數列\((a_i)_{i\in \mathbb{N}}\)
定義 \(S_k = \sum^k_{i=1}{a_i}\)
則數列在區間 [a b] 的值為 \(S_b - S_{a-1}\)
要做什麼??
當一個問題詢問很多關於區間的問題,如果直接算
當詢問次數很多
則每次都需要花費區間 b - a + 1 這麼多次,假設每次都是問 1 ~ n 就需要花費 n 次,加上詢問次數 Q 這樣總共需要 Qn 次。
但是如果使用前綴和,我們需要花 n 次來建立 partial sum 陣列,但是我們每次詢問都只要花費一次減法 \(S_b - S_{a-1}\) 就好了。
所以這樣總共只需要 q + n 次
注意
因為 \(S_b - S_{a-1}\) 我們在建造 partail sum 需要 index 從 1 開始,不然會跑到 -1 陣列會出事。
練習
function
例子
引入變數
回傳不同型態
return
函式的呼叫
前後定義的問題
解決方法
我喜歡的寫法
我喜歡的寫法 EOF 版本
why
可以直接 return
區域、全域變數
區域變數
起始於變數宣告,結束於宣告敘述所在的區塊的大右括號。
全域變數
全域變數
注意事項
練習題