CPE數學系
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    {%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> ## CPE 題目檢討 前三題我只會講個大概,題目沒有很困難,可以自行練習 --- ### 第一題 (給大家五分鐘看題目) https://cpe.cse.nsysu.edu.tw/cpe/file/attendance/problemPdf/10041.pdf ---- ### 題目 沒有仔細看題目的話可能會被騙 (這我) 題目大概: 選定任何一個當初始點,到每一個點的距離和要最小 ---- ### 思路 - 排序 - 暴力每一點 or 懂的話直接找中位數 - 然後得到距離和最小的點 --- ### 第二題 (給大家五分鐘看題目) https://cpe.cse.nsysu.edu.tw/cpe/file/attendance/problemPdf/573.pdf ---- ### 題目 蝸牛白天可以爬 3,晚上睡覺時滑下來 1 。每一天爬的長度,都會比第一天爬的還要少 10%,也就是 3\*0.10 = 0.3。現在問你在第幾天這個蝸牛可以爬離這個井 (高度 $>H$ 才算爬出井口,$<0$ 才算掉入井底,這個訊息題目沒寫,對,當下要從側資判斷 = =) ---- ### 思路 - 利用模擬算出天數。注意每次上升長度的衰減是減個定值,並非每次去乘上一個比例 - 但需要注意每天上升的高度最低為 0。 (小關鍵) --- ### 第三題 (給大家五分鐘看題目) https://cpe.cse.nsysu.edu.tw/cpe/file/attendance/problemPdf/11233.pdf ---- ### 題目 以下為複數形式的輸出說明: 若單字的複數形態屬於沒有規則的類型,請從表格輸出對應的複數型(表格會事先給定)。 否則,若單字以子音字母接"y"結尾,請以"ies"取代"y"。 否則,若單字以"o", "s", "ch", "sh", "x"結尾,請在字尾多加上"es"。 否則,請直接在字尾加上"s"。 ---- ### 思路 - 第一種用 map 一對一 - 再來一堆 if else 判斷剩下的幾種 - 若單字以子音字母接"y"結尾,請以"ies"取代"y"。 請注意是"子"音 --- ### 第四題 (給大家五分鐘看題目) https://cpe.cse.nsysu.edu.tw/cpe/file/attendance/problemPdf/1118.pdf ---- 題目: S(n, m) = mS(n − 1, m) + S(n − 1, m − 1) 把 n 個數,分成 m 個聯集的總和 ---- ### 思路 (超簡單 DP) - 初始化: n 個數分成 1 個就是只有一種 n 個數 分成 n 個也是一種 - 看測資大小,可以直接簡單 top-down 的方式,然後用 map 紀錄算過的 (避免重複運算) - 或者你可以逆推回 button-up (記得用預處理,不要每次都重新處理) 下面使用 top-down 方法演示 ---- ### top-down 複雜度 $O(n^2)$ ```cpp= int dp[1005][1005]; int n, m; int S(int n, int m) { if (n == m || m == 1) return 1; if (dp[n][m] != 0) return dp[n][m]; int sum = (m * S(n - 1, m) + S(n - 1, m - 1)) % 2; dp[n][m] = sum; return sum; } void solve() { cin >> n >> m; cout << S(n, m) % 2 << endl; } // main 多筆測資處理 ``` --- ### 第五題 (給大家五分鐘看題目) https://cpe.cse.nsysu.edu.tw/cpe/file/attendance/problemPdf/340.pdf ---- ### 題目 題目敘述: 1A2B 遊戲,給定一個正確答案,然後根據每個猜測輸出 XAYB ,A代表相同位置相同數字,B代表不同位置相同數字 ---- ### 思路 - 此題重點在於你可能會用到重複的數字,例如 答案 2222,猜測 1234,正確應該是 1A0B - 所以先簡單判斷 A 有幾個,並且記錄該位置已經被算過了 (不要重複計算) - 再來暴力計算 B 有幾個,同時要記得紀錄該位置被算過了 - 根據題目要求格式輸出(前面四個空格) ---- ### 簡單的實作而已 ```cpp= void solve(int n) { vector<int> ans(n); // 答案 for (int i = 0 ; i < n ; i++) cin >> ans[i]; while (true) { int A = 0, B = 0; vector<int> guess(n), ch(n); // 猜測 和 紀錄判斷位置 for (int i = 0 ; i < n ; i++) cin >> guess[i]; if (guess[0] == 0) return ; // 自己做剩下的主要判斷 cout << " (" << A << "," << B << ")" << endl; } } int main(void) { int test = 1, t; while (cin >> t) { if (t == 0) return 0; cout << "Game " << test << ":" << endl; solve(t); test++; } } ``` --- ### 第六題 (給大家十分鐘看題目) https://cpe.cse.nsysu.edu.tw/cpe/file/attendance/problemPdf/580.pdf ---- ### 題目 題目: 有單一元素U和L,要求把n個元素排成一行同時要求至少有3個U在一起,問有幾種方法? ---- ### DP 思路,需要仔細思考一下 - 全部排列數 - 不符合的組合數 - 定義 dp(i, j) 為 i 個元素 j = 0 代表以 L 結尾 j = 1 代表以 U 結尾 j = 2 代表以 UU 結尾 - 初始化 dp(1, 0) = dp(1, 1) = 1, dp(1, 2) = 0 ---- ### 實作 ```cpp= int dp[35][5]; void build() { dp[1][0] = 1, dp[1][1] = 1; dp[1][2] = 0; for (int i = 2 ; i <= 30 ; i++) { dp[i][0] = dp[i-1][0] + dp[i-1][1] + dp[i-1][2]; dp[i][1] = dp[i-1][0]; dp[i][2] = dp[i-1][1]; } return ; } int main(void) { build(); int t; while (cin >> t) { if (t == 0) return 0; cout << (1 << t) - dp[t][0] - dp[t][1] - dp[t][2] << endl; } } ``` ---- ### 暴力搜 這題有人說可以暴力搜 DFS 大家可以試試看? 但不是初衷所以不講 ---- ### 作弊小兔仔子 眼尖的大家可以發現,這題目只有 30 筆測資 而 CPE 是可以人工手輸測資,並且按下 人工test,會幫你產生答案 於是你可以先搞出答案後 ```cpp= vector<int> ans = {1, 12, 1234, 12345}; //這邊是亂打的,然後30個 void solve(int n) { cout << ans[n-1] << endl; } ``` --- ### 第七題 (1分鐘快速看一看) https://cpe.cse.nsysu.edu.tw/cpe/file/attendance/problemPdf/10229.pdf ---- ### 題目 題目: 要求輸出費式數列第 n 項 mod $2^m$ 注意: $0 ≤ n ≤ 2147483647$,所以不能用 $O(N)$ 的 DP 解 ---- ### $O(logN)$ 解 - 矩陣快速冪 上課講過囉! --- ### 結尾 祝大家考試順利! ![image](https://hackmd.io/_uploads/BkirpLmQC.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    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.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully