[学习/笔记]ACM课程内容笔记(I)

ACM课程内容笔记(I)

2020/8/30

此文档发布在博客园
视频来源于 https://www.bilibili.com/video/BV1pE411E7RV?p=1
文档格式: txt
如有纰漏敬请斧正

<Using fake-markdown 1.0.0>

 


 

C++ 与 STL

1.C++标准语法    

    (1) cin慢于scanf

      读10E5以上的数据应当使用scanf,cin会导致TLE(超时)
    (2) C++ 语法特性
      a. 动态分配内存
        不支持变长数组
        平时写题可以不释放内存
      b. 引用
        用于简化指针的代码
      c. 函数重载
      d. struct
        允许加入构造函数
   2.C++标准库
    (1)概述
      <vector> <string> <algorithm> <queue> <stack> <set> <functional> <complex>
    (2)回顾C标准库
      a. cstring
        size_t strlen(const char *str) 获取字符串长度
        strcmp() 字符串比较
        strcpy() 字符串拷贝
        memset()暴力清空
          逐字节填写

1 memset(str,0,sizeof(str));//使用0填充整个str
2 memset(str,-1-sozeof(str));//见DP
3 memset(i,0x3f3f3f3f,sizeof(i))//使用最大值填充i

        memcpy()暴力拷贝
      b.cmath
      c.cstdlib
        qsort()
          不常用。快速排序,速度真的快(真香!)
        rand()
        malloc()
        free()
      d.ctime
        time(0)
          从1970年到现在的秒数,用于srand(time(0))
        clock()
          程序启动到目前位置的秒数

          用于计时,单位为ms。
      e.cctype
        isdigit()
        isalpha()
          判断是不是数字/字符
    (3)vector
      1.声明
        可变长度数组
          vector<int> arr1(100);
        可以把vector看成链表
          vector<int> arr1;
      2.push_back()在最后加入元素
      3.vector的遍历
        迭代器(iterator)
          一种指针,通过迭代器可以获得每个元素。用法和普通指针相同
          vector<int>::iterator p = arr1.begin();
      4.常见操作
        size();    //元素个数
        clear();   //清空数组
        empty();   //判断数组是否为空
        begin();   //返回首元素迭代器
        end();    //返回末元素迭代器

        erase(iterator i);  //删除i迭代器所在处的元素
        push_back(...);    //向数组后面添加元素
        pop_back();      //删除最后一个元素

    (4)string
      字符串
        可以看成vector<char>...
      1.string 包含了vector的操作
      2.常见操作
        .length()
        .size()
        .insert(1,"aaa")
        .insert(str.begin(),'a')
        .c_str()
        .append(another_str) 将another_str拼接到后面
        .compare(another_str) 即strcmp(str,another_str)
    (5)algorithm
      提供了很多算法
      1.sort()
        复杂度:O(nlogn)

1 int arr[]={2,4,1,5,4}
2 int n = 5;
3 sort(arr,arr+n);
4 sort(begin,end,cmpMethod)

        (cmpMethod 排序依据)
        内部排序是按小于关系来的
          e.g.

1 bool cmp(Point a,Point b)
2 {
3     if(a.x != b.x)
4     {
5         return a.x<b.x
6     }
7     return a.y<b/y
8 }    

        也可以重载操作符
      2.min()
      3.max()
      4.min_element()
      5.max_element()

      6.nth_element(begin,pos,end) 对第n小(从0开始算)的数放到第n个位置,部分快排

      7.swap()
      8.reverse()
      9.unique()
        要先sort,用于“线段树和树状数组”
        int newLength = unique(arr.begin(),arr.end())-arr.begin();
      10.lower_bound()
        upper_bound()
        二分查找,排好序的数组中找到位置
          lower查找下界
          upper查找上界

    (6)stack
      后进先出
    (7)queue
      队列,先进先出
     priority_queue
      优先队列
    (8)set
      集合,在O(logn)的时间内查找、删除、添加某个元素
      自带去重
     unordered_set
      可以重复元素
    (9)map
      map 映射
      pair 配对
     unordered_map
    (10)bitset
      表示二进制,可以用下标访问,也可以进行位运算
    (11)funcational
      配合priority_queue
    (12)complex
      复数类
    (13)一键包含
      #include <bits/stdc++.h>
      ** vs不能用
      内容见附件
  3.参考
    https://www.cplusplus.com
  4.细节
    (1) 1s时限能进行的操作大概为1e8
    (2) G++在输出double不能用%lf,用%f
    (3) 注意多组用例EOF、初始化
    (4) const INF = 0x3f3f3f3f

  5.stdc++.h

 1 // C
 2 #ifndef _GLIBCXX_NO_ASSERT
 3 #include <cassert>
 4 #endif
 5 #include <cctype>
 6 #include <cerrno>
 7 #include <cfloat>
 8 #include <ciso646>
 9 #include <climits>
10 #include <clocale>
11 #include <cmath>
12 #include <csetjmp>
13 #include <csignal>
14 #include <cstdarg>
15 #include <cstddef>
16 #include <cstdio>
17 #include <cstdlib>
18 #include <cstring>
19 #include <ctime>
20 
21 #if __cplusplus >= 201103L
22 #include <ccomplex>
23 #include <cfenv>
24 #include <cinttypes>
25 #include <cstdalign>
26 #include <cstdbool>
27 #include <cstdint>
28 #include <ctgmath>
29 #include <cwchar>
30 #include <cwctype>
31 #endif
32 
33 // C++
34 #include <algorithm>
35 #include <bitset>
36 #include <complex>
37 #include <deque>
38 #include <exception>
39 #include <fstream>
40 #include <functional>
41 #include <iomanip>
42 #include <ios>
43 #include <iosfwd>
44 #include <iostream>
45 #include <istream>
46 #include <iterator>
47 #include <limits>
48 #include <list>
49 #include <locale>
50 #include <map>
51 #include <memory>
52 #include <new>
53 #include <numeric>
54 #include <ostream>
55 #include <queue>
56 #include <set>
57 #include <sstream>
58 #include <stack>
59 #include <stdexcept>
60 #include <streambuf>
61 #include <string>
62 #include <typeinfo>
63 #include <utility>
64 #include <valarray>
65 #include <vector>
66 
67 #if __cplusplus >= 201103L
68 #include <array>
69 #include <atomic>
70 #include <chrono>
71 #include <condition_variable>
72 #include <forward_list>
73 #include <future>
74 #include <initializer_list>
75 #include <mutex>
76 #include <random>
77 #include <ratio>
78 #include <regex>
79 #include <scoped_allocator>
80 #include <system_error>
81 #include <thread>
82 #include <tuple>
83 #include <typeindex>
84 #include <type_traits>
85 #include <unordered_map>
86 #include <unordered_set>
87 #endif
View Code

 

posted @ 2020-09-01 00:30  二氢茉莉酮酸甲酯  阅读(248)  评论(0编辑  收藏  举报