随笔分类 - 算法竞赛
摘要:#include <bits/stdc++.h> using namespace std; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int>
阅读全文
摘要:尽量只对无符号数使用移位运算 右移:丢弃最低位,向下取整,(-1>>1的结果是-1) 左移:有符号数 位运算的优先级,除了取反符高于算术运算符,其他符号都低于算术运算符。 其中& | ^的优先级甚至低于比较运算符。 判断是否是二的非负整数次幂: bool isPowerOfTwo(int n) {
阅读全文
摘要:struct TrieNode { int cnt; int nxt[26]; void Init() { cnt = 0; memset(nxt, 0, sizeof(nxt)); } }; struct Trie { static const int MAXN = 4000000; TrieNo
阅读全文
摘要:struct SegmentTree { #define ls (o<<1) #define rs (o<<1|1) static const int MAXN = 100000; int cnt[(MAXN << 2) + 5]; void PushUp(int o) { cnt[o] = cnt
阅读全文
摘要:下面代码的删除部分是有错的,不能用!!!应该是del[0]没有在Init的时候清空。另外这些函数也太难用了。 代码 /* Treap : 完整版 */ struct Treap { private: static const int TREAP_MAXN = 2e5 + 5; static cons
阅读全文
摘要:加上logn计算第k大的方法,就可以用于通过“普通平衡树”这道题。 struct BinaryIndexTree { static const int MAXN = 500000 + 10; int n, A[MAXN]; int cnt[MAXN], siz[MAXN]; void InitVal
阅读全文
摘要:维护点权信息,记得涉及线段树的操作都要套一个tid变换成线段树上的坐标。 struct TreeChain { static const int MAXN = 100000 + 10; struct Edge { struct EdgeNode { int v, nxt; } en[MAXN <<
阅读全文
摘要:题目链接:https://codeforces.com/contest/1467/problem/E 观察 对于某种权值 \(val\) ,若点 \(i\) 的权值 \(a[i]=val\) 则把这个点染成黑色,其他的点染成白色。 定义黑色节点的数量,为权值 \(val\) 的出现次数 \(cnt[
阅读全文
摘要:商场有n个物品,每个物品有一个价格a[i],每个物品至多购买1次。商场有m个折扣活动,用(x[i],y[i])表示一次购买x[i]个物品可以免去最便宜的y[i]个物品的价格。问购买恰好k个物品的最小总价格。 https://codeforces.com/contest/1154/problem/F
阅读全文
摘要:int n; namespace MoAlgorithm { static const int MAXM = 3e5 + 10; static const int MAXN = 3e5 + 10; int n, m, BLOCK; struct Node { int l, r, id; bool o
阅读全文
摘要:狄尔沃斯定理:最小路径覆盖=最长反链 最小不相交路径覆盖:使用最小条数的路径,覆盖每个点恰好1次。 最小可相交路径覆盖:使用最小条数的路径,每个点可以覆盖多次。 最小可相交路径覆盖做一次Floyd传递闭包变成最小不相交路径覆盖。 最小不相交路径覆盖使用二分图匹配:把每个点x拆成x1(出度)和x2(入
阅读全文
摘要:允许重边,不允许自环。 无向图: 度数矩阵:D[i][i]=deg[i] 邻接矩阵:A[i][j]=edge[i][j]的数量 注意不可以有自环 Laplace矩阵: L=D-A 生成树个数记为 \(t(G)\) 无向图矩阵树定理: 对于所有的i,把Laplace矩阵的第i行和第i列删除,然后计算其
阅读全文
摘要:列主元GaussJordan消元法 struct Matrix { static const int MAXN = 505; static const int MAXM = 505; int n, m; long double A[MAXN][MAXM]; long double x[MAXM];
阅读全文
摘要:使用方法 使用下列代码定义一个以seed为伪随机数种子的uint32范围内的伪随机数生成器: mt19937 rnd(seed); 定义完成后,使用下列代码生成若干个uint32范围内的伪随机数,并将其赋值给uint32类型变量r0, r1, r2, r3,它们极大概率互不相同: mt19937 r
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; typedef long long ll; #define ls ch[id][0] #define rs ch[id][1] const int INF = 1e9; const int MAXN = 100
阅读全文
摘要:ll fac[18]; int n, k, c; int last[18]; void show() { printf("k=%d\n", k); for(int i = 1; i <= c; ++i) printf("%d%c", last[i], " \n"[i == c]); } void S
阅读全文
摘要:int dis[200005]; int fa[200005][20]; void dfslca(int u, int p) { dis[u] = dis[p] + 1; fa[u][0] = p; for(int i = 1; i < 20; ++i) fa[u][i] = fa[fa[u][i
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define debug(a) cout << #a << ": " << a << endl #defi
阅读全文
摘要:https://codeforces.com/contest/2/problem/C 随机移动算法。 double x[4], y[4], r[4]; double dis(double X, double Y, int id) { double len = sqrt(sq(X - x[id]) +
阅读全文
摘要:stack<int> S; vector<int> circle; int dep[100005]; void dfs(int u, int p, int d) { dep[u] = d; if(!circle.empty()) return; //printf("u=%d\n", u); vis[
阅读全文

浙公网安备 33010602011771号