{%hackmd @hipp0\Hippotumuxthem %}
<style>
.text-center{
text-align: center; //文字置中
}
.text-left{
text-align: left; //文字靠左
}
.text-right{
text-align: right; //文字靠右
}
</style>
<style>
.reveal .slides {
text-align: left;
font-size:30px;
}
</style>
# 複習
---
HC01
https://ncuma-oj.math.ncu.edu.tw/problem/HC01
----
```cpp=
// input our data
int dp[n+5] = {0};
dp[1] = 1, dp[2] = 1;
for (int i = 2 ; i < n ; i++)
dp[i+1] = (s[i] == s[i-2]) ? dp[i+1-2] + 1 : 1;
for (int i = 0 ; i < q ; i++) {
int l, r, l1, r1, l2, r2;
cin >> l >> r;
l1 = l + ((l & 1) == 0);
l2 = l + (l & 1);
r1 = r - ((r & 1) == 0);
r2 = r - (r & 1);
if (dp[r1] - dp[l1] + 1 == ((r1 - l1)>>1) + 1 && dp[r2] - dp[l2] + 1 == ((r2 - l2)>>1) + 1) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
```
---
<h3 style='color:#C4C400'> 函式呼叫函式 </h3>
```cpp=
void IPass(){
cout<<"PASS";
}
void IFail(){
cout<<"FAIL";
}
void sayResult(int score){
if (score >= 60)
IPass();
else
IFail();
}
int main(){
int score;
cin >> score;
sayResult(score);
}
```
----
<h3 style='color:#C4C400'> 自己呼叫自己 </h3>
```cpp=
void say_hello(){
cout << "Hello~" << '\n';
say_hello();
}
```
----
### 注意
必須有結束條件,或是在某些條件下才呼叫自己,這樣才有醒來的機會。
----
<h2 style='color:#C4C400'> 遞迴</h2>
----
<h3 style='color:#C4C400'> 費波那契數列 </h3>
費波那契定義如下
第0項 = 0
第1項 = 1
第k項 = 第 k-1 項 + 第 k-2 項
----
```cpp=
int f(int n){
if (n == 0) return 0;
else if (n == 1) return 1;
else return f(n-1) + f(n-2);
}
```
----
<h3 style='color:#C4C400'> 練習題 </h3>
C003
C004
{"title":"複習","description":"HC01","contributors":"[{\"id\":\"b4bc52a4-04a8-4c6d-920a-32b9ab31a7f9\",\"add\":1649,\"del\":0}]"}