Upgrade to Pro — share decks privately, control downloads, hide ads and more …

師大資工系ACM-ICPC讀書會:貳、排序搜尋與數學基礎

Cd57bf203d03722597a5c88007eb1c17?s=47 Maplewing
October 22, 2013

 師大資工系ACM-ICPC讀書會:貳、排序搜尋與數學基礎

Cd57bf203d03722597a5c88007eb1c17?s=128

Maplewing

October 22, 2013
Tweet

Transcript

  1. 貳、排序搜尋與數學基礎 師大資工系 灆洢 取自於<提升程式設計的邏輯思考力> 5.3 & 5.4

  2. 排序搜尋

  3. •2 5 8 7 6 3 9 •2 5 7

    8 6 3 9 •2 5 7 6 8 3 9 •2 5 6 7 8 3 9 •2 5 6 7 3 8 9 •2 5 6 3 7 8 9 泡沫排序法 Bubble Sort •2 5 3 6 7 8 9 •2 3 5 6 7 8 9
  4. •| 2 5 8 7 6 3 9 •2 |

    5 7 8 6 3 9 •2 3 | 7 8 6 5 9 •2 3 5 | 8 6 7 9 •2 3 5 6 | 8 7 9 •2 3 5 6 7 | 8 9 選擇排序法 Selection Sort •2 3 5 6 7 8 | 9 •2 3 5 6 7 8 9 |
  5. 插入排序法 Insertion Sort •| 2 5 8 7 6 3

    9 •2 | 5 7 8 6 3 9 •2 5 | 7 8 6 3 9 •2 5 7 | 8 6 3 9 •2 5 7 8 | 6 3 9 •2 5 6 7 8 | 3 9 •2 3 5 6 7 8 | 9 •2 3 5 6 7 8 9 |
  6. 快速排序法 Quick Sort •2 5 8 7 6 3 9

    •2 3 5 8 7 6 9 •2 3 5 8 7 6 9 •2 3 5 7 6 8 9 •2 3 5 6 7 8 9 •2 3 5 6 7 8 9 •2 3 5 6 7 8 9
  7. 合併排序法 Merge Sort •2 5 8 7 6 3 9

    •2 5 8 7 6 3 9 •2 5 7 8 3 6 9 •2 5 7 8 3 6 9 •2 5 7 8 3 6 9 •2 3 5 6 7 8 9
  8. 線性搜尋 Linear Search (Find: 8) •2 3 5 6 7

    8 9 •2 3 5 6 7 8 9 •2 3 5 6 7 8 9 •2 3 5 6 7 8 9 •2 3 5 6 7 8 9 •2 3 5 6 7 8 9 •2 3 5 6 7 8 9
  9. 二元搜尋 Binary Search (Find: 8) •必定先排序好! •2 3 5 6

    7 8 9 •2 3 5 6 7 8 9
  10. 範例一:Number Chains (UVa 263)

  11. 範例二:Word Amalgamation (UVa 642)

  12. •340 •10420 •10474 •152 •299 •120 作業 •156 •400 •123

    •10194 •755 •10785
  13. 數學基礎

  14. •檢查n是否為質數: •2~n-1 是否整除之 •2~sqrt(n) 是否整除之 •2 & 3,5,7,9…sqrt(n) 是否整除之 質數:一般作法

  15. •6n, 6n+1, 6n+2, 6n+3, 6n+4, 6n+5 •6n: 2*(3n) •6n+2: 2*(3n+1)

    •6n+3: 3*(2n+1) •6n+4: 2*(3n+2) 質數:跳貳跳肆法
  16. • 2, 3, 4, 5, 6, 7, 8, 9, 10,

    11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 • 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 • 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 • 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 • 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 • 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 • 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 • 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 • 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 • 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 • 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 質數:篩法
  17. • (x1,y1), (x2,y2), (x3,y3), (x4,y4) …… 幾何:多邊形面積 x1 x2 x3

    x4 …….. y1 y2 y3 y4 …….. •實線相乘 •黃色相加 •綠色相減
  18. • 點在多邊形內 幾何:判斷點在多邊形內 • 點在多邊形上 • 點在多邊形外

  19. 幾何:由拉公式 •多凸邊形:V-E+F=2 • V:頂點數 •E:邊數 • F:面數

  20. 範例一:Count on Cantor (UVa 264)

  21. 範例二:Factors and Factorials (UVa 160)

  22. 範例三:Orchard Trees (UVa 143)

  23. 範例四:How Many Pieces of Land ? (UVa 10213)

  24. •113 •10161 •253 •621 •10025 •591 作業:雜題 •107 •573 •846

    •10499 •10790 •11044 •10719 •10177 •10916 •10970 •10014
  25. •575 •10110 •550 •568 •408 •350 作業:數論 •10061 •10392 •10879

  26. •10250 •579 •375 •10387 •10112 作業:幾何

  27. 謝謝聆聽 資料取自於<提升程式設計的邏輯思考力> 5.3 & 5.4