<h2 class="text-center">CPE 檢定加強計畫(二)</h2> <h3 class="text-center">簡單數學</h3> <style> :root{ --r-main-font-size: 30px; } .reveal .slides { text-align: left; } /* .ul-left { display: block !important; margin:0 0 0 0.5em !important; } */ .hint { color: #191919; } details[open] { margin-top: 1.5em; } details[open] .hint { color: inherit; } details[open] .hint::after { content: ":"; } </style> ---- ### Table of Contents - 好用的C++語言數學工具 - 常見級數公式 - 中位數 - 微積分 - 基本例題講解 --- <h2 class="text-center">好用的 C++ 語言工具</h2> ---- ### 排序 sort() ```cpp int n = 5; int arr[n] = {5, 1, 8, 6, 7}; sort(arr, arr + n); // O(nlogn) 排序 ``` ---- ### 求冪次 pow() ```cpp cout << pow(2, 10) << '\n'; // 1024 cout << pow(2, -2) << '\n'; // 0.25 cout << pow(2, 0.5) << '\n'; // 1.41421 (根號 2) ``` *回傳值是浮點數,可能產生誤差 --- <h2 class="text-center">常見級數公式</h2> ---- ### 等差級數公式 $$ \begin{aligned} S_n &= \frac{(a_1 + a_n) n}{2} \\ &= \frac{2a + (n - 1) d}{2} \cdot n \end{aligned} $$ 推導請點[這裡](https://hackmd.io/@ShanC/Hk1mufmHC#/7/3) <!-- .element: class="fragment" data-fragment-index="1" --> ---- ### 等比級數公式 有限項: $S_n = \begin{cases} a \cdot \dfrac{1 - r ^ n}{1 - r}, & r \neq 1 \\ an, & r = 1 \end{cases}$ 無限項(收斂): $S_\infty = \dfrac{a}{1-r}, \quad 0 < r < 1$ 推導請點[這裡](https://hackmd.io/@ShanC/Hk1mufmHC#/7/7) <!-- .element: class="fragment" data-fragment-index="1" --> ---- ### 累加級數公式 $$ \begin{aligned} \sum_{k = 1}^{n} k &= 1 + 2 + 3 + \cdots + n = \frac{n (1+n)}{2} \\ \sum_{k = 1}^{n} k^2 &= 1^2 + 2^2 + 3^2 + \cdots + n^2 = \frac{n (n+1) (2n+1)}{6} \\ \sum_{k = 1}^{n} k^3 &= 1^3 + 2^3 + 3^3 + \cdots + n^3 = \Biggl[\frac{n (n+1)}{2}\Biggr]^2 \end{aligned} $$ 推導請點[這裡](https://hackmd.io/@ShanC/Hk1mufmHC#/6/4) <!-- .element: class="fragment" data-fragment-index="1" --> --- <h2 class="text-center">中位數</h2> ---- ### 如何找中位數? 排序後取中間值,如果 $n$ 是偶數就中間兩者相加後除以 $2$ ```cpp int n = 5, ans; int arr[n] = {5, 1, 8, 6, 7}; sort(arr, arr + n); // 排序 if(n % 2 == 0) // 如果 n 是偶數 ans = (arr[n / 2] + arr[n / 2 - 1]) / 2; else // 如果 n 是奇數 ans = arr[n / 2]; cout << ans << '\n'; ``` --- <h2 class="text-center">微積分</h2> ---- ### 微分 $$ \begin{aligned} f(x) &= a_nx^n + a_{n-1}x^{n-1} + \cdots + a_2x^2 + a_1x + a_0 \\ f'(x) &= na_{n}x^{n-1} + (n-1)a_{n-1}x^{n-2} + \cdots + 2a_2x + a_1 \end{aligned} $$ ---- ### 積分 微分反著做 ||自己去翻課本|| --- <h2 class="text-center">基本例題講解</h2> ---- <!-- .slide: data-transition="fade" --> <h3 class="text-left" > <a href="https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1753">10812 - Beat the Spread!</a> </h3> 有兩支隊伍在比賽 給你兩支隊伍的分數和與差的絕對值 要你求出兩支隊伍的分數分別是多少 :::spoiler <font color=#191919>提示</font> 國中代數題 ::: ---- <!-- .slide: data-transition="fade" --> <h3 class="text-left" > <a href="https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=982">10041 - Vito's family</a> </h3> 給你數線上 $r$ 個點 找出其中一點 $P$ 使其他點到 $P$ 的距離最近 並求出其他點到 $P$ 的距離總和 :::spoiler <font color=#191919>提示</font> 找中位數 $m$,並找出大家跟 $m$ 的距離 ::: ---- <!-- .slide: data-transition="fade" --> <h3 class="text-left" > <a href="https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=242&page=show_problem&problem=3170">12019 - Doom's Day Algorithm</a> </h3> 給你日期,要算出此日期是 $2011$ 年的星期幾 :::spoiler <font color=#191919>提示</font> 可以把該年已經過了的天數加一加再 $mod ~7$ 就可以找出答案 ::: ---- <!-- .slide: data-transition="fade" --> <h3 class="text-left" > <a href="https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2456">11461 - Square Numbers</a> </h3> 求兩數間有幾個完全平方數 :::spoiler <font color=#191919>提示</font> 因數字很小,可以建表來判斷是否是完全平方數 也可以直接透過浮點入運算來判斷 ::: ---- <!-- .slide: data-transition="fade" --> <h3 class="text-left" > <a href="https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=997">10056 - What is the Probability?</a> </h3> 有 $n$ 人玩遊戲,每次獲勝機率 $p$ 如果遊戲沒人獲勝就繼續玩下去 直到有玩家贏為止 求第 $i$ 人獲勝的機率 ---- <!-- .slide: data-transition="fade" --> <h3 class="text-left" > <a href="https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1209">10268 - 498-bis</a> </h3> 題目給 $n$ 次多項式降冪排列的係數與 $x$ 的值 求其微分後的答案 ---- <!-- .slide: data-transition="fade" --> <h3 class="text-left" ><a href="https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1012"> 10071 - Back to High School Physics </a></h3> 高中物理學過吧 代公式即可 :::spoiler <font color=#191919>提示</font> $$ \begin{aligned} v_t &= v_0+at, a = vt \\ S_t &= \frac{d}{dt} \bigl[v_t\bigr] = v_0t + \frac{1}{2} at^2 \\ S_{2t} &= v_0(2t) + \frac{1}{2} a(2t)^{2} \\ &= 2t (\cancel{v_0} + \cancel{\frac{1}{2}} \times \cancel{2} at) \\ &= 2t(at) = 2vt \end{aligned} $$ ::: ---- <!-- .slide: data-transition="fade" --> <h3 class="text-left" ><a href="https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2004"> 11063 - B2-Sequence </a></h3> 題目寫得很直白 給你一串數字,看是否符合定義 --- 以上是本章內容 [題目連結](https://vjudge.net/contest/653052) <a href="https://github.com/ShanCisgood/cpp_for_uva" style="color: #191919">答案在這裡</a>
{"description":"好用的C++語言數學工具","title":"簡單數學","slideOptions":"{\"transition\":\"fade\"}","contributors":"[{\"id\":\"4f67a8cd-06ae-45dc-a8e3-62c6a41e5a37\",\"add\":7670,\"del\":2445},{\"id\":\"dbf3352a-4a61-4739-9e70-396b6f72e250\",\"add\":2196,\"del\":1838}]"}
    214 views
   Owned this note