Review 2020-2021

知识点,题型,模板,易错点,刷题中碰到的有用的小撇步小巧思还有语法问题都统一汇总在这里

  • String 
    • s.subtr(pos) pos to end or s.substr(pos, len)
    • repeating a single char multiple times: string(times, char)
    • istringstream/ostringstream/stringstream ss(input s); while (ss>tmp) 对tmp操作
  •  (1p3a)根据数据规模选择算法:考虑计算机是1 GHz,程序的overhead大概是100,也就是说计算机每秒能够运算106 到 107 次。一般来讲超过1秒的程序会超时,所以可以根据数据规模简单判断可以选用的算法:
                    a. N > 105, 需要log(n)算法,主要是二分法
                    b. 1000 < N < 10000, 一般是O(n),也是个人感觉难题集中的地方,算法多变性很多,比如指针,dp
                    c. 1000 < N < 5000, 这个时候可能会出现O(nlogn)算法,一般就是排序
                    d. 100 < N < 1000, 这是允许 O(n^2) 算法,两次遍历数据,或者DP
                    e. 10 < N < 100, 基本看到这个数据量就是NP问题了,组合O(2^n) 或者排列O(n!)
  •   Basics
    • Sorting
      • merge sort Time O(nlogn) Space O(n)
        • divide and conquer 把一个list不停一拆二一拆二拆到每个小sublist都只有一个元素了,再合二为一合二为一,合的过程中排序,最后合成一个sorted list
      • quick sort Time O(nlogn) Space O(logn)
        • 任意挑一个数做pivot,把比它小的全部移到它左边,比它大的全部移到它右边,针对左右这两个区再各自进行同样的操作分区,以此类推
      • heap sort Time O(nlogn) Space O(1)
  • Binary Search
    • 对坐标二分,针对有序数组
    • 对值本身二分
    • 应用二分的思想
    • rotated sorted array
  • Linked List
    • 调整顺序
    • 快慢指针
  •  BFS
    • graph traversal
    • 最短路径
    • find all
  • Bit Manipulation
    • 判断odd:n&1
    • The operators &, ^, and | are bitwise operators when the operands are primitive integral types. They are logical operators when the operands are boolean

posted @ 2020-08-05 16:14  little_veggie  阅读(82)  评论(0)    收藏  举报