Algorithm game review

The study summary for more than four months one after another, the specific questions and solutions are below:

After writing this summary, I did some real questions. It turns out that some features are not in line with the compiler version of the competition, so some basic conversions are not enough, and there are some strange inputs. Others are fine. I thought about it. , This game doesn't test many algorithms, what do you do with so many weird inputs.


String problem, union search set and large number problem (and base system) need to be added


Container and algorithm part

Have a certain understanding of the following containers and the use of different types of arrays:
string,
vector, list, deque,
queue, stack,
priority_queue
set, unorder_set,
map, unorder_map
father array, tree array
a[] a[][] a[] [][]

algorithm库的使用 max,min
*max_element,*min_element
sort,heap_sort
next_permutation
fill memset
swap
reverse
lower_bound,upper_bound

Algorithm part

Summary link

1. Recursion {①1.92. Recursively implement exponential enumeration ②. 93. Recursively implement combined enumeration ③. 94. Recursively implement permutation enumeration}
.
2. dfs {①Maze problem ②Fixed direction path number problem ③Queen problem (dfs+backtracking)}
.
3. bfs and inverse bfs {①labyrinth problem ②shortest path for long read from single source to single source unit}
.
4. Backtracking (dfs+backtracking) {①Total arrangement problem ②Bracket generation and parenthesis matching problem ③Queen problem ④Island problem}
.
5. Minimal spanning tree (kruscal+ and search set) {①The problem of the minimum cost of abstract connection into points ②The problem of village (city) access}
.
6. The shortest path from single source to multiple sources (dijkstra) {the shortest distance from a certain point i to any other point}
.
7. Multi-source to multi-source (floyd) {abstract as n point pairwise shortest path problem}
.
8. Topological sorting {To do a series of things, you need preconditions ①course schedule}
.
9.dp{ 1) Linear dp: ①Path problem ②Nine lectures on backpack ③Non-adjacent backpack ④Sequence sum and sequence maximum value problem ⑤Memory search dsf+dp 2) Interval dp: ① Interval dp is converted to linear dp, the longest Common subsequence}
.
10. Various sorts {insertion sort, binary insertion sort, hill sort, selection sort, heap sort, bubble sort, merge sort, fast sort}
.
11. Mathematical problems (GCD, fast power, matrix fast power) {①GCD ②fast power ③matrix fast power ④naive prime number ⑤Angstrom sieve ⑥Euler sieve}
.
12. Prefix sum {①One-dimensional prefix sum ②Sub-matrix and ③tree array solve the problem of prefix sum and dynamic array insertion}
.
13. Dichotomy idea {Find an open interval, so that ans must be in the interval, between half partitions, and bipartite (there is only one interval with ans) ans must be at the right end of the left interval, or the left end of the right interval point. Therefore, every time l or r is updated, it is set as the end point of the interval. In the end, it exists if the endpoint is ans, otherwise it does not exist.
① Template 1: Confirm that ans is in the left interval -> r=m; the calculation of m remains unchanged. ②Template 2: Confirm that ans is in the right interval ->l=m;
the calculation of m should be changed to: m=(l+r+1)/2;}

. ================================================== =========
.
The last things to learn:
1. set map operation √
2. Dichotomy, prefix and √
3. A recursive question 1h33' -2h6'
4. A simulation sort: 1h9' -1h25'
5. Tree array, line segment tree √ ⚪
6. Greed


Digression: Disable cin and stdio synchronization, cin and cout speed is the same as scanf printf
ios::sync_with_stdio(false);

dfs+backtracking (dfs violent dfs pruning)

1. Number of islands

2. The largest area of ​​the island

3. Full arrangement

4. Eight Queens (n ​​Queens)

5. Solve the maze

6. Step on the square

7. 2n queen (variant of n queen)

8. Bracket generation

9. The shortest path from single source to single source

(This is the same as the maze. It is enough to return to the shortest path. There is also a pruning technique. Once tem_len>min_len returns directly,
the vernacular is, if in the process of path length accumulation, once the current accumulated length is greater than the original storage The shortest length of, then there is no need to continue walking, just return directly)

10. Shield god and weight weighing

BFS

1. Solving the maze
2. The shortest path (the length of the grid is 1, without weight)
3. 01 matrix
4. Dungeon master
5. Global warming

Minimum spanning tree -------- kruscal (unified search)

1. The village is electrified [template]
2. And check the collection-template questions + practice questions

Single source shortest path dijkstra

1.dijkstra

Topological sort

1. Course schedule
2. Course schedule Ⅱ (derivative of the course schedule)

Excel

Get the date quickly:
Insert picture description here
Insert picture description here
Insert picture description here

Dynamic programming DP

Classic DP question (custom ordering of simple leetcode questions)

1) Path knapsack problem dp
2) Sequence linear dp problem
3) Interval dp
1. Knapsack nine lectures

2. Search dfs+memo (memorized search)
1. Classic skiing questions

2. Increasing the longest path (change of the ski problem)

3. Tebonacci (optimized algorithm used for over-large data)

4. Fibonacci (optimized algorithm used for over-large data)

5. The frog jumps the stairs (Fibonacci change)


Greedy Type Questions

Individual-Greedy Algorithm-Summary
Greedy 2


Recursion

1. 92. Recursively implement exponential enumeration
2. 93. Recursively implement composite enumeration
3. 94. Recursively implement permutation enumeration

Various sorts

Find Sort


Dichotomy

Personal summary-two points

simulation

gold

Math problem

Fast power
GCD Fast power matrix Fast power
prime + divisor


Prefix and

Find the sum of prefixes and sub-matrices, tree arrays and line segment trees

Container use
0. Basic operations of set and map, unordered_set and unorded_map

1. The most frequent integer

2. Use of STL full permutation function

3. Sliding window ordinary and monotonic queue solution

4.all_sort

ASCII

Any type of conversion

Addition, deletion, modification, and order of containers

Initial state

Strings and character arrays

String overall case conversion function

Familiar algorithm: enumerate violence for dfs bfs backtrack and find the minimum spanning tree topological sort

Mathematical algorithm: fast power gcd lcm

Ensuring the correctness of the input

Types of test cases

Analysis of time complexity

Guess you like

Origin blog.csdn.net/BOWWOB/article/details/108197239