
算法
Coder_小庞
这个作者很懒,什么都没留下…
展开
-
矩阵相关算法
2.矩阵的行列式按行展开,递归求解原创 2022-05-31 21:14:27 · 208 阅读 · 0 评论 -
《算法基础》 动态规划-背包问题
《算法基础》 动态规划-背包问题文章目录《算法基础》 动态规划-背包问题1. 01背包问题2.完全背包问题3.多重背包问题4.分组背包问题最核心最简洁的的代码:1.01背包问题for (int i = 1; i <=n; i ++) for (int j = m; j >= v[i]; j --) { f[j] = max(f[j], f[j - v[i]] + w[i]); }2.完全背包问题for (int原创 2022-01-01 12:12:44 · 373 阅读 · 0 评论 -
《算法基础》 约数
《算法基础》 约数文章目录《算法基础》 约数1.试除法求约数2.求约数个数3.约数之和4.欧几里得算法1.试除法求约数#include <iostream>#include <algorithm>#include <cstring>using namespace std;vector<int > get_divides(int n){ vector<int > res; for (int i = 1; i <= n原创 2021-06-17 22:52:55 · 162 阅读 · 0 评论 -
《算法基础》 数学知识-素数
《算法基础》 数学知识-素数文章目录《算法基础》 数学知识-素数1.埃氏筛法2.线性筛法埃氏筛法 和 线性筛法 时间复杂度差不多,在10^7的情况下,线性筛法比埃氏筛法快一倍。1.埃氏筛法#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int N = 1000010;int prime[N], cnt;bool st[N];/原创 2021-06-14 22:56:32 · 158 阅读 · 0 评论 -
《算法基础》 二分图
《算法基础》 二分图文章目录《算法基础》 二分图1.染色法判断二分图1.染色法判断二分图#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int N = 100010, M = 200010;int h[N], e[M], ne[M], idx;int color[N];int n, m;void add(int a, int原创 2021-06-04 17:13:13 · 156 阅读 · 0 评论 -
《算法基础》 最小生成树算法
《算法基础》 最小生成树算法文章目录《算法基础》 最小生成树算法1.Prim_最小生成树算法1.Prim_最小生成树算法源代码:#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int N = 510, INF = 0x3f3f3f3f;int g[N][N];int dist[N]; //dist[i] 表示i这个点到 集原创 2021-06-02 20:40:57 · 141 阅读 · 0 评论 -
《算法基础》 图论 -- 最短路
《算法基础》 最短路问题文章目录《算法基础》 最短路问题前言1.朴素版Dijkstra算法前言朴素版 Dijkstra算法 O(n ^ 2) 的 适合于稠密图 也就是边比较多的图稠密图 m = n ^ 2 用邻接矩阵来存储 稀疏图 m = n 用邻接表来存储堆优化的Dijkstra算法 O(mlog n) 的 n 和 m 是同一个量级的n 表示 顶点 m表示边若 n m <10 ^ 5 尽量使用 堆优化的Dijstra 算法1原创 2021-05-28 09:37:24 · 292 阅读 · 1 评论 -
《算法基础》 树和图
《算法基础》 树和图文章目录《算法基础》 树和图1.树和图的基本操作2. 例题:树的重心1.树和图的基本操作#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int N = 100010, M = 2 * N;int n;int h[N], e[M], ne[M], idx;int vis[N];void add(int a,原创 2021-05-13 22:01:34 · 134 阅读 · 0 评论 -
《算法基础》 DFS
《算法基础》 DFS文章目录《算法基础》 DFS1.排列数字2. n皇后1.排列数字#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int N = 10;int path[N];int vis[N];int n;void dfs(int u){ if (u == n) { for (int i =原创 2021-05-11 20:40:24 · 115 阅读 · 0 评论 -
《算法基础》 哈希算法
《算法基础》 哈希算法文章目录《算法基础》 哈希算法1.哈希表--拉链法2.哈希表--开放寻址发3.哈希字符串1.哈希表–拉链法#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int N = 100003; //找大于 10^5 的第一个质数, 这样冲突才会最小化int h[N], e[N], ne[N], idx;i原创 2021-05-04 16:47:54 · 119 阅读 · 0 评论 -
《算法基础》Trie树,并查集,堆
《算法基础》Trie树,并查集,堆文章目录《算法基础》Trie树,并查集,堆前言一. Trie树二. 数组模拟双链表三. 数组模拟栈和队列四. 列题:单调栈和单调队列前言为什么要用数组来模拟链表,栈和队列那? 这些不是在STL中都有吗 ?其实一句话, 最主要的原因就是快。一. Trie树源代码:#include <iostream>#include <algorithm>#include <cstring>using namespace std原创 2021-05-01 20:29:05 · 268 阅读 · 2 评论 -
《算法基础》 KMP算法
《算法基础》 KMP算法文章目录《算法基础》 KMP算法我觉得 KMP 算法的核心 就是相等 a = b, b = c, 那么a = c.源代码:#include <iostream>#include <algoirthm>using namespace std;const int N = 100010, M = 1000010;int n, m;int ne[N];char s[M], p[N];int main(){ cin >> n原创 2021-04-24 11:19:43 · 93 阅读 · 0 评论 -
《算法基础》数组模拟链表、栈和队列
《算法基础》数组模拟链表、栈和队列文章目录《算法基础》数组模拟链表、栈和队列前言一. 数组模拟单链表二. 数组模拟双链表三. 数组模拟栈和队列四. 列题:单调栈和单调队列前言为什么要用数组来模拟链表,栈和队列那? 这些不是在STL中都有吗 ?其实一句话, 最主要的原因就是快。一. 数组模拟单链表源代码:#include <iostream>#include <algorithm>using namespace std;const int N = 100原创 2021-04-24 11:15:39 · 142 阅读 · 0 评论 -
《CSP认证真题》2020-6-1 1.线性分类器
《CSP认证真题》2020-9-4 4.星际旅行文章目录《CSP认证真题》2020-9-4 4.星际旅行#include <iostream>#include <algorithm>#include <cstring>using namespace std;typedef long long LL;int n, m;struct Point{ int x, y; char c;}p[1010];int get(int a, int b,原创 2021-04-06 22:26:20 · 274 阅读 · 0 评论 -
《CSP认证真题》2020-9-4 4.星际旅行
《CSP认证真题》2020-9-4 4.星际旅行文章目录《CSP认证真题》2020-9-4 4.星际旅行#include <iostream>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const int N = 110, M = 2010;int n, m;double R;double o[N], p[M][N];d原创 2021-04-04 18:20:20 · 322 阅读 · 0 评论 -
《算法笔记》离散化
《算法笔记》离散化文章目录《算法笔记》离散化 此题第一次看确实没看懂,所以此处略作分析,为什么要离散化呢,因为存储的下标实在太大了,如果直接开这么大的数组,根本不现实,第二个原因,本文是数轴,要是采用下标的话,可能存在负值,所以也不能,所以有人可能会提出用哈希表,哈希表可以吗?答案也是不可以的,因为哈希表不能像离散化那样缩小数组的空间,导致我们可能需要从-e9遍历到1e9(此处的含义就是假如我们需要计算1e-9和1e9区间内的值,那我们需要从前到后枚举,无论该值是否存在),因为哈希表不能排序转载 2021-03-31 19:43:49 · 160 阅读 · 0 评论 -
《CSP认证真题》2013-12-5 5.I’m stuck
《CSP认证真题》2013-12-5 5.I’m stuck!文章目录《CSP认证真题》2013-12-5 5.I’m stuck!#include <iostream>#include <algorithm>#include <cstring>using namespace std;int n, m;char map[60][60];bool st1[60][60], st2[60][60];int dirx[] = {-1, 0, 1,原创 2021-03-23 18:56:51 · 126 阅读 · 0 评论 -
《CSP认证真题》 2013-12-5 4.有趣的数
《CSP认证真题》2013-12-5 4.有趣的数文章目录《CSP认证真题》2013-12-5 4.有趣的数源代码:#include <iostream>#include <algorithm>#include <cstring>using namespace std;typedef long long ll;const int mod = 1e9 + 7;int n;int c[1010][1010];int ans;int mai原创 2021-03-22 19:19:27 · 124 阅读 · 0 评论 -
《蓝桥杯算法》滑动窗口问题
《蓝桥杯算法》滑动窗口问题文章目录《蓝桥杯算法》滑动窗口问题一、最长不重复子序列二、字符串匹配三、字符串匹配2一、最长不重复子序列源代码:#include <iostream>#include <map>#include <string>using namespace std;string s;int l, r;int match;map<char, int > window;int ans = 1 << 31;原创 2021-03-21 19:44:07 · 325 阅读 · 0 评论 -
《蓝桥杯算法》N皇后问题
《蓝桥杯算法》N皇后问题文章目录《蓝桥杯算法》N皇后问题源代码:#include <iostream>#include <cmath>using namespace std;int n;int queen[1000]; //第i行的皇后应该放在第queen[i]列的位置void nQueen(int k) //第k列的皇后安排好位置后, 安排第k+1的位置{ if( k == n){ for(int i = 0; i < n; i++){原创 2021-03-14 17:20:01 · 283 阅读 · 0 评论 -
《蓝桥杯算法》给定子矩阵的和
《蓝桥杯算法》给定子矩阵的和文章目录《蓝桥杯算法》给定子矩阵的和源代码:#include <iostream>using namespace std;int a[1010][1010];int sum[1010][1010];int main(){ int n , m; scanf("%d%d" , &n, &m); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){原创 2021-03-07 19:45:07 · 85 阅读 · 0 评论 -
《蓝桥杯算法》最长子序列和最大矩阵的和
《蓝桥杯算法》最长子序列和最大矩阵的和文章目录《蓝桥杯算法》最长子序列和最大矩阵的和一、最长子序列1.暴力算法(时间复杂度(O(n^2))2.动态规划(时间复杂度(O(n))二、最大子矩阵1.暴力算法(时间复杂度(O(n^6))2.略微优化(时间复杂度(O(n^4))3.动态规划(时间复杂度(O(n^3))一、最长子序列1.暴力算法(时间复杂度(O(n^2))源代码:#include <iostream>using namespace std;int main(){ in原创 2021-03-07 19:30:39 · 302 阅读 · 0 评论