The time complexity of the search operation in the ordered sequence can be optimized to log N level array. Obtain the starting subscript [start] and the ending subscript [end] of the search part for T and the number to be searched [x]. Calculate the intermediate bisection point Subscript [mid], which is the average of start and end

Read more

Basic solution [O(N^2)] T is the input sequence, and F is the length of the longest ascending subsequence ending with the i-th number. It can be obtained that F[i] is equal to F[0...i – 1], which satisfies T. [i] > T[0…i – 1] For example, the sequence T = {1, 5, 6, 4, 2, 9} corresponds to F = {1, 2, 3, 2, 2, 4} F The largest number in the sequence is the longest ascending subsequence

Read more

1. In a relational database, the logical structure of the data stored in the database is mainly two-dimensional tables. 2. The meaning of ASCII code is American Standard Code for Information Interchange. 3. There is no algorithm that can determine whether an infinite loop will occur for any program and corresponding input data. Therefore, any compilation system does not perform infinite loop testing. 4. ∧ = and丶∨ = or 丶¬ = negation.

Read more

It is used to quickly find which set a certain point is in. It is often used in questions about graphs. You can check Luogu P3367 question. #include #define _for(i, n) for(int i = 0; i < n; i++) using namespace std; const int MAXN = 1e6 + 100; int m, n, o, x, y; int map[MAXN]; int find(int u) { if(map[u] != u) map[u] = find(map[u

Read more

struct nodef { string name; int score; bool operator <(const nodef &n) const { return this -> score < n.score; } }; These sentences indicate that a structure named nodef is created, and its member variables are: Name and score are overloaded with the operator <, which means that when a nodef and nodef are used for < operation, the second nodef is passed in as parameter n, and the return value of the operation is bool type, and the comparison basis is the score variable.

Read more

序列式容器 向量[vector] 列表[list] 双端队列[deque] 适配器容器 栈[stack] 队列[queue] 优先队列[priority_queue] 关联式容器 集合[set] 多重集合[multiset] 映射[map] 多重映射[multimap] 完整XLSX文件传送门

Read more

BFS – 广度优先遍历 一种利用队列实现的搜索算法。简单来说,其搜索过程和 “湖面丢进一块石头激起层层涟漪” 类似。形象一点如下: 总的来说,就是先遍历离根节点近的,一层一层的。 程序思路 函数传入需要遍历的树/图的根节点,然后将根节点放入队列,开始循环操作,只要队不是空的,就取队首并且将队首元素所连接的点放入队中。 要注意的是,图中可能出现环,可能会陷入死循环,所以要定义一个数组记录节点是否被访问过。 实现方法 – 存储方式为点对点 广度优先遍历,参数v是开始遍历的点

Read more

Create an array point-to-point, using subscripts to represent different points, and using its content to represent the points connected to this point. For example, if the array is named graph, then graph[0] = 1 can be used to indicate that point 0 can lead to point 1. Among them, if a point can be connected to multiple points, it can be stored in a two-dimensional array. For example, graph[0][0] = 1 and graph[0][1] = 2 means that the point connected to point 0 has 1 point and 2:XNUMX. Normally, the second dimension of this two-dimensional array will not be filled, so you can use a vector as the second dimension, like this: #include using namespace std; const int M

Read more

Used for traversal access by some special classes, similar to a pointer. The following uses vector[vector] as an example: How to create an iterator: list ::iterator it; Commonly used operations, iterator traversal: for(it = l.begin(); it != l.end(); it++) Among them, l is a list type variable, first the iterator is equal to l The first address is then added to the tail address of l PS: In most STL, the tail address points to an empty element, so use! = Access the iterator: print(%d, *it); This means outputting the list

Read more