11 2023 档案
摘要:1.稠密图用邻接矩阵来存 朴素版dijkstra 算法 acwing 849 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 const int N = 510; 5 int n,m; 6 int dis[N]; //每个点到起点的最短距离(
阅读全文
摘要:1. 1 /如何手写一个堆?完全二叉树 5个操作 2 //1. 插入一个数 heap[ ++ size] = x; up(size); 3 //2. 求集合中的最小值 heap[1] 4 //3. 删除最小值 heap[1] = heap[size]; size -- ;down(1); 5 //4
阅读全文
摘要:用于字符串的插入和查询 1.acwing835 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 const int N = 100010; 5 int son[N][26]; //trie树中每个点的所有儿子 6 int cnt[N],idx
阅读全文
摘要:1.Problem - 1791D - Codeforces 定义函数 f()f() 表示字符串 x 中不同字符的数量。 现给定一个字符串 S,将它分割为两个字符串 a,b。求出:max(f()+f())max(f(a)+f(b))。 我们可以搞一个前缀和 a 和一个后缀和 b,分别表示 f
阅读全文
摘要:位与: 可以看作乘法& 只有当两位都为1结果才为1,否则为0 位或: 可以看作不进位加法| 只有当两位都为0的时候结尾才为0,否则为1 异或 : ^ 当两位不同的时候结尾才为1,否则为0; 按位取反:0变1,1变0; 1.P1469 找筷子 - 洛谷 | 计算机科学教育新生态 (luogu.com.
阅读全文
摘要:1.P2240 【深基12.例1】部分背包问题 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 算性价比,进行排序来进行局部最优解 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int t,n; 5 6 struct no
阅读全文
摘要:1.区间划分 acwing 905 按照区间右端点来排序,如果当前点能覆盖到则继续往下读,如果不能覆盖到则点数加一,该点更新为下一个区间的最右端点 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int n; 5 const int N =
阅读全文
摘要:1.区间dp P1063 [NOIP2006 提高组] 能量项链 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 对于环形问题,我们常常可以采用将n个元素复制成2n个元素,或者选择(i + 1) % n的形式 第一次遇到区间dp,写个题解总结一下 区间dp能解决的问题就是通过小区间
阅读全文
摘要:动态规划过程是: 每次决策依赖于当前状态,又随即引起状态的转移。一个决策序列就是在变化的状态中产生出来的,所以,这种多阶段最优化决策解决问题的过程就称为动态规划(DP)。 基本思想与策略 基本思想与分治法类似,也是将待求解的问题分解为若干个子问题(阶段),按顺序求解子阶段,前一子问题的解,为后一子问
阅读全文
摘要:1.数字三角形。acwing 898. 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 const int N = 520,INF = 1e9; 5 int n; 6 int a[N][N]; //表示每一个点 7 int f[N][N];
阅读全文
摘要:1. 01背包问题 二维表示 对于01背包一维优化的一点理解:二维转化为一维:删掉了第一维:在前i个物品中取。f[j]表示:拿了总体积不超过j的物品,最大总价值。 为何能转化为一维?二维时的更新方式:f[i][j]=max(f[i - 1][j] ,f[i - 1][j - v[i]] + w[i]
阅读全文
摘要:1.树的重心 acwing 846 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 5 using namespace std; 6 7 const int N = 1e5 + 10; //数据范围是10的5次方
阅读全文
摘要:DFS : acwing 842 递归搜索树 题库 - AcWing 1 #include<iostream> 2 using namespace std; 3 4 const int N = 10; 5 int n; 6 int path[N]; 7 bool st[N]; 8 9 void df
阅读全文
摘要:kmp 算法基本思路 1.初始化 j = -1,表示 pattern 当前已被匹配的最后位。2.让 i 遍历文本串 text,对每个 i,执行 3、4来试图匹配 text[i] 和 pattern[j + 1]。3.直到 j 回退到 -1 或者是 text[i] == pattern[j + 1],
阅读全文
摘要:acwing 154滑动窗口,单调队列q 存的是下标,真正的值需要再套一个a数组 1 #include<iostream> 2 using namespace std; 3 4 const int N = 1e6 + 10; 5 6 int n,k; 7 int a[N],q[N]; //q代表单调
阅读全文
摘要:1.并查集模板 P3367 【模板】并查集 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int N = 2e5 + 10; 5 int n,m,x,y,z;
阅读全文
摘要:1.哈希表的使用 <1> 拉链法 1 #include <cstring> 2 #include <iostream> 3 4 using namespace std; 5 6 const int N = 1e5 + 3; // 取大于1e5的第一个质数,取质数冲突的概率最小 可以百度 7 8 //
阅读全文
摘要:1.Otoshidama - AtCoder abc085_c - Virtual Judge (vjudge.net) 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int n,Y; 5 6 int main() 7 { 8 while(
阅读全文
摘要:1.单链表 https://www.acwing.com/problem/content/828/ 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 const int N = 100010; 5 6 7 int head,e[N],ne[N]
阅读全文
摘要:1.Good Distance - AtCoder abc133_b - Virtual Judge (vjudge.net) 判断是否为整数,用开方后平方判断是否相等,并且此题将多对数 成数组来输出 1 #include <bits/stdc++.h> 2 using namespace std;
阅读全文
摘要:1.Counting Roads - AtCoder abc061_b - Virtual Judge (vjudge.net) 利用数组的值去替换数组的下标来简化计数过程 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int n,m,a
阅读全文
摘要:1.Coins - AtCoder abc087_b - Virtual Judge (vjudge.net) 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 long long a,b,c,x,ans; 5 int main() 6 { 7
阅读全文
摘要:1.B - Beautiful Strings (atcoder.jp) 代码: 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int n; 5 int cnt[500]; 6 string s; 7 int mian() { 8 cin
阅读全文
摘要:一维前缀和 1 #include<iostream> 2 using namespace std; 3 4 const int N = 100010; 5 int n,m; 6 int a[N],s[N]; //初始化s[0] = 0 7 8 int main() 9 { 10 scanf("%d%
阅读全文
阅读目录(Content)
此页目录为空