随笔分类 -  算法

摘要:https://www.acwing.com/problem/content/242/ #include<iostream> using namespace std; const int N=100010; int n,m; int p[N],d[N]; int find(int x){ if(p[ 阅读全文
posted @ 2022-01-17 20:34 秋月桐 阅读(86) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/833/ #include<iostream> using namespace std; const int N=100010,M=1000010; int n,m; int ne[N]; //next array cha 阅读全文
posted @ 2022-01-14 10:50 秋月桐 阅读(32) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/832/ #include<iostream> using namespace std; const int N=100010; int stk[N],tt=0;//tt指向当前栈顶,数据区1开始 int main(){ 阅读全文
posted @ 2022-01-07 22:03 秋月桐 阅读(40) 评论(0) 推荐(0)
摘要:rt 实现任意 b 进制转换 10 进制 注意:b<=10 //秦九邵算法 //b 进制转10 进制 int get(string s,int b){ int res=0; for(auto c:s){ res=res*b+c-'0'; } return res; } 更新: 1-35任意进制 转换 阅读全文
posted @ 2022-01-02 20:57 秋月桐 阅读(232) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; const int N=100010; int head,e[N],ne[N],idx; void init(){ head=-1; idx=0; } void add_to_head(int x){ e[idx]=x; 阅读全文
posted @ 2022-01-02 13:43 秋月桐 阅读(53) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; const int N=100010; int n,m; int q[N]; int main(){ scanf("%d%d",&n,&m); for(int i=0;i<n;i++) scanf("%d",&q[i]) 阅读全文
posted @ 2022-01-02 13:42 秋月桐 阅读(38) 评论(0) 推荐(0)
摘要:序列和 #include<iostream> using namespace std; const int N=100010; int a[N],b[N]; int main(){ int n,m,l,r; cin>>n>>m; for(int i=1;i<=n;i++) cin>>b[i]; fo 阅读全文
posted @ 2022-01-02 13:41 秋月桐 阅读(75) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; const int N=100010; int q[N],s[N]; int main(){ int n; cin>>n; for(int i=0;i<n;i++) cin>>q[i]; int res=0; for(i 阅读全文
posted @ 2022-01-02 13:40 秋月桐 阅读(42) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; const int N=1e6+10; int n,q[N],tmp[N]; void quick_sort(int q[],int l,int r){ if(l>=r) return; int x=q[l+r>>1], 阅读全文
posted @ 2022-01-02 13:39 秋月桐 阅读(38) 评论(0) 推荐(0)
摘要:#include<iostream> #include<algorithm> using namespace std; const int N=100010; int q[N],tmp[N]; long int res; void merge_sort(int q[],int l,int r){ i 阅读全文
posted @ 2022-01-02 13:39 秋月桐 阅读(29) 评论(0) 推荐(0)
摘要:背景:离散化一词常常见到,甚至很多算法题不自觉的都会用到,比如hashmap,根据value找key等(内置find效率较低),根据acwing的例题总结了一下: 例题:https://www.acwing.com/problem/content/804/ 所谓离散化,就是将一些定义域很大的数,但总 阅读全文
posted @ 2021-12-26 18:45 秋月桐 阅读(85) 评论(0) 推荐(0)
摘要:基本并查集建立 并查集是一种合并不相交集合的数据结构 ,常用在寻找图中是否存在环路 建立并查集就是在建立一个尽量平衡的树。边建立边检测是否存在环路 最重要的两点: 找到根节点 find_root(x) 合并两棵树 union(xTree,yTree) #include <stdc++.h> usin 阅读全文
posted @ 2021-12-02 21:34 秋月桐 阅读(363) 评论(0) 推荐(0)
摘要:路径规划07 1575. 统计所有可行路径 今天又是一道hard呢,加油干碎它,干碎这道题就进入进阶部分了 先从记忆化搜索开始(因为普通dfs会超时) 普通dfs步骤: 1.递归函数的入参和出参确定 2.递归出口 Base Case 3.编写最小单元的逻辑 通常Base Case 是最难的部分 cl 阅读全文
posted @ 2021-11-30 10:23 秋月桐 阅读(47) 评论(0) 推荐(0)
摘要:路径规划06 1289. 下降路径最小和 II 本题和上一题没有太大区别,就是注意用两个变量保存上一行的dp最小值和次小值 #include <cstring> class Solution { public: int minFallingPathSum(vector<vector<int>>& g 阅读全文
posted @ 2021-11-28 22:01 秋月桐 阅读(46) 评论(0) 推荐(0)
摘要:路径规划05 931. 下降路径最小和 class Solution { public: int minFallingPathSum(vector<vector<int>>& matrix) { int m=matrix.size(); int n=matrix[0].size(); //先假设从第 阅读全文
posted @ 2021-11-27 23:01 秋月桐 阅读(48) 评论(0) 推荐(0)
摘要:路径规划04 三角形动态规划 class Solution { public: int minimumTotal(vector<vector<int>>& triangle) { int dp[200][200]; memset(dp,0,sizeof(dp)); //状态转移方程:dp[i][j] 阅读全文
posted @ 2021-11-25 20:26 秋月桐 阅读(53) 评论(0) 推荐(0)
摘要:路径规划03 在前两个题基础上问题换成了求最小路径和 64. 最小路径和 class Solution { public: int minPathSum(vector<vector<int>>& grid) { //状态转移方程 //dp[i][j]=min(dp[i-1][j],dp[i][j-1 阅读全文
posted @ 2021-11-25 20:25 秋月桐 阅读(54) 评论(0) 推荐(0)
摘要:路径规划02 在路径规划01中加一个障碍物 63. 不同路径 II class Solution { public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { int m=obstacleGrid.size() 阅读全文
posted @ 2021-11-25 20:24 秋月桐 阅读(45) 评论(0) 推荐(0)
摘要:动态规划之路径规划01 前言:虽然自己做过几个动态规划的题目,看过题解后也能做出几个二维的路径问题,主要是对dfs进行优化。但是还是有点知其然不知其所以然的感觉,有两个月左右没做dp,现在让我写对一个二维路径dp都困难。所以开这个专题系统学习dp。 感谢:宫水三叶 本笔记根据三叶大佬的刷题日记进行学 阅读全文
posted @ 2021-11-25 20:22 秋月桐 阅读(433) 评论(0) 推荐(0)
摘要:lowbit函数的实现 lowbit函数实现有两种方式: 一、 x&(x^(x-1)) 二、 x&-x 用lowbit运算统计1的个数 我们可以使用lowbit运算统计一个整数的二进制形式下1的个数。 实现原理很简单啦,就是:我们先用lowbit运算找出lowbit(x)lowbit(x),然后用原 阅读全文
posted @ 2021-10-19 21:33 秋月桐 阅读(476) 评论(0) 推荐(0)