随笔分类 - Algorithm
摘要:Links https://www.renfei.org/blog/bipartite-matching.html https://en.wikipedia.org/wiki/Matching_(graph_theory) Hungarian Algorithm Given a matching M
阅读全文
摘要:HDU 1164 #include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl using namespace std; typedef long long LL; const int MAXN = 65535 +
阅读全文
摘要:Implementation #include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl using namespace std; typedef long long LL; void qsort(vector<i
阅读全文
摘要:Stars Two dimensional binary indexed tree. #include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl using namespace std; typedef long
阅读全文
摘要:236. Lowest Common Ancestor of a Binary Tree If we can find two subtrees of root such that both of them has target, then root is the LCA of p and q. I
阅读全文
摘要:Unique Binary Search Trees class Solution { public: int numTrees(int n) { // We consider the position of node n in the tree first. // Because all node
阅读全文
摘要:33. Search in Rotated Sorted Array class Solution { public: int search(vector<int>& nums, int target) { int l = 0, r = nums.size() - 1; while (l <= r)
阅读全文
摘要:Comparison sorts Name Best Average Worst Memory Stable Bubble sort \(n\) \(n^2\) \(n^2\) $1$ Yes Insertion sort \(n\) \(n^2\) \(n^2\) $1$ Yes Merge so
阅读全文
摘要:通过观察递归实现,用循环和栈模拟递归实现中结点入栈和出栈的过程。 #include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl using namespace std; typedef long long LL; s
阅读全文
摘要:https://leetcode.com/problems/median-of-two-sorted-arrays/ 函数$kth$表示归并两个数组时得到的第$k$个元素,函数的计算过程为,每次从$A$或$B$数组的其中一个数组中,找出$p$个元素,这$p$个元素不大于归并得到的第$k$个元素,接着
阅读全文
摘要:HDU 1880 #include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl using namespace std; typedef long long LL; const unsigned int KEY =
阅读全文
摘要:[kuangbin专题] Manacher 实现参考了https://oi-wiki.org/string/manacher/。 POJ 3974 Palindrome 求字符串$A$的最长回文子串模板题,首先在$A$的第一个字符的左面和$A$的每个字符的后面填充不在输入范围内的字符$,得到串$S$
阅读全文
摘要:https://hihocoder.com/problemset/problem/1093 实现参考了算法导论。 #include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl using namespace std;
阅读全文
摘要:模板 const int N = 1000000 + 16; struct Hash { const unsigned long long KEY = 137; unsigned long long h[N], p[N]; int len; void init(const int a[], int
阅读全文
摘要:https://hihocoder.com/contest/offers108/problems A 再买优惠 暴力或二分一下 #include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl using namespa
阅读全文
摘要:按照查询的边权w排序,离线add和query,注意树剖处理边权时的特殊逻辑。 #include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl #define lrrt int L, int R, int rt #def
阅读全文
摘要:Max answer 与POJ 2796 Feel Good类似,但是这个题有负数,需要特殊处理一下 #include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl using namespace std; typed
阅读全文
摘要:令$sum_{i, j}\(表示从\)(i, j)\(开始沿着\)(i - 1, j), (i - 2, j) \dots (0, j)$方向的连续的$1$的个数, \[ sum_{i, j} = \begin{cases} 0 & m_{i, j} \ne 1 \\ 1 + sum_{i - 1,
阅读全文
摘要:有数组$A[N], 1\le N \le 3 \cdot 105$, $P$次查询,对于每次查询给出$pos$和$k$,求$\sum\limits_{pos + m \cdot k \le N} A[pos + m \cdot k]$。 把所有查询按$k$分组,$k \le \sqrt N$的组$O
阅读全文
摘要:简单二维偏序 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #define DBG(x) cerr << #x << " = " << x << endl
阅读全文

浙公网安备 33010602011771号