12 2017 档案
摘要:强烈推荐 "这篇文章" ,一下子就看懂AC了。 cpp include include include using namespace std; typedef long long ll; struct Edge{ int too, nxt; }edge[200005]; int n, m, r,
阅读全文
摘要:我们想知道 $2^{2^{2^\cdots}}\mod p$。 考虑用扩展欧拉定理降幂, $$2^{2^{2^\cdots}}\equiv 2^{(2^{2^\cdots}\mod \varphi(p))+\varphi(p)}\mod p. $$ 于是定义$f(p)=2^{2^{2^\cdots}
阅读全文
摘要:扩展欧拉定理: $$ a^x \equiv a^{x\mathrm{\ mod\ }\varphi(p) + x \geq \varphi(p) ? \varphi(p) : 0}(\mathrm{\ mod\ }p)$$ cpp include include include using name
阅读全文
摘要:发现好像没人来证明贪心啊……那我来写一下它的证明 欲证明:放一个数在已有的柱上(如果可以)总是比新开一个柱更优的 假如已经放了 现在我要放 我有两种策略 在 (`xu xx`组成完全平方数的数)上放,或者新开一个柱子 即 or 然后再考虑 对于 ,上下两种都是一样的,就不说了 既然 可以与 组成完全
阅读全文
摘要:$$\sum a_i x\times \sum b_i $$ 等同于 $$ \sum(a_i x \times b_i) $$
阅读全文
摘要:最小路径覆盖, "看这里" cpp include include include include using namespace std; struct Edge{ int too, nxt, val; }edge[15005]; int n, m, hea[305], ss, tt, uu, v
阅读全文
摘要:倘若某个试题已经被选到某个类型里了,那么它就不可再被选进别的类型了。 所以,对于每个类型,我们将其与汇连边,权值是它的要求的题目数量。 对于每个题目,我们将源与其连边,权值是1,代表只能用一次。然后再将其与它所对应的所有类型连边。 倘若最大流小于m,则说明不能组卷。 输出路径我觉得还是比较好做的,对
阅读全文
摘要:最大权闭合子图 参考 "这" ,胡伯涛论文。 10,8,6,3这个简单割对应的闭合子图是A1,B1,B2 输出路径时,最后一次层次图中,与源点相连的点即选做的实验,与汇点相连的点即选用的仪器。 cpp include include include include using namespace s
阅读全文
摘要:状压最短路 cpp include include include include using namespace std; struct Node{ int bi1, bi2, fi1, fi2; }nd[105]; int n, m, ww[105], cnt, dis[1050005]; bo
阅读全文
摘要:源向地球连 月球向汇连 每一天往下一天连 飞船上一天与这一天连 枚举答案 cpp include include include include using namespace std; struct Edge{ int too, nxt, val; }edge[1000005]; int n, m
阅读全文
摘要:网络流不用动脑子的好爽啊 cpp include include include include using namespace std; int n, uu, hea[105], cnt, ss, tt, sum, minCost, pre[105], dis[105]; const int oo
阅读全文
摘要:匈牙利 cpp include include include using namespace std; int n, m, lst[105], uu, vv, cnt, ans; bool edge[105][105], vis[105]; bool dfs(int x){ for(int i=m
阅读全文
摘要:ss是源点,代表餐巾卖家,tt是汇点,代表记账收钱者。 记p(i)是i天早晨的可用毛巾数,q(i)是i天完了的废毛巾数。 建图见注释 cpp include include include include using namespace std; typedef long long ll; int
阅读全文
摘要:luogu 匈牙利算法 cpp include include include using namespace std; int n, m, uu, vv, e, lnk[1005], ans; bool a[1005][1005], vis[1005]; bool dfs(int u){ for(
阅读全文
摘要:每次选代价最小的流增广 cpp include include include include using namespace std; struct Edge{ int too, nxt, val, cst; }edge[100005]; int n, m, ss, tt, maxFlow, mi
阅读全文
摘要:当前弧优化 cpp include include include include using namespace std; int n, m, ss, tt, hea[10005], cnt, uu, vv, ww, maxFlow, cur[10005]; int lev[10005]; con
阅读全文
摘要:练一下最大流 cpp include include include include using namespace std; int n, m, ron[205][205], pre[205], uu, vv, ww, vis[205]; queue d; int ek(){ int maxFlo
阅读全文
摘要:dp[i]表示第一队打饭时间i的最优解 cpp include include include include using namespace std; struct Node{ int aa, bb; }nd[205]; int n, sum[205], dp[40005], ans=0x3f3f
阅读全文
摘要:就是一步一步把大的往目标地放。 cpp include include using namespace std; int fro[55], too[55], cnt, uu, n, ans=0; void dfs(int x, int qu){ if(fro[x]==qu) return ; for
阅读全文
摘要:搜索+背包就是了 cpp include include include using namespace std; int n, m, a[25], ans=0, lst=0; bool isu[25], f[2005]; void dfs(int x){ if(x==m+1){ int cnt=0
阅读全文
摘要:点 $ (i,j) $ 会看不见当有 $ k|i $ 且 $ k|j$ 时。 然后就成了求欧拉函数了。 cpp include include include using namespace std; int n, phi[40005], pri[40005], cnt; bool isp[4000
阅读全文
摘要:hdu1787,直接求欧拉函数 poj2478,欧拉函数递推,证明可以看 "这里" 或者是算法竞赛进阶指南 $n \log n$ 筛 cpp include include include using namespace std; int n; long long phi[1000005]; voi
阅读全文
摘要:好题。 网上看到的范围是:$T \leq 10$,$ n \leq 50000$, $ a_i,b_i \leq 10^9$。 我们按照贪心惯常的思路考虑交换相邻的两个人。容易发现,对于相邻的两个人,总是后一个人的答案更大一点。而我们的目的,是让两个人中后一个人的答案更小(这样可以让这两个人后面的答
阅读全文
摘要:先排个序然后做最长上升子序列就行了。 cpp include include include using namespace std; struct Node{ int ll, ww; }nd[50005]; int n, cnt, dp[5005]; bool cmp(Node x, Node y
阅读全文
摘要:好的题解使人一下就懂啊…… s1[i][j]表示(i,j)最多向左(或右)延伸多少个格子,使这些格子中的数都是0(不包括(i,j)) s2[i][j]表示(i,j)最多向上延伸多少个格子,使这些格子中的数都是0(不包括(i,j)) f[i][j]表以(i,j)为右下(左下)角的最大对角线长度 来自
阅读全文
摘要:倒着推就是了 cpp include include include using namespace std; int n, k, p, t, dp[10005]; vector a[10005];//是他,就是他!我们的英雄vector! int main(){ cin n k; for(int
阅读全文
摘要:如果prime[i]是k的因子,那么【k \ (在prime[i]以后的质数)】等于【prime[i]\ (k/prime[i])\ (这个质数)】,一定被筛过了,所以这里可以break。 cpp include include include using namespace std; bool i
阅读全文
摘要:先是维修数列 题解看 "这里" ,但是我写的跑得很慢 下面是poj的,稍加改动即可ac洛谷。 如果想看题意分析及讲解请看 "这里" ,讲得很好,一下就让我明白splay维护区间了。 splay的价值在于维护区间,如果只是维护点的话完全可以用treap等平衡树代替
阅读全文
摘要:悬线法 cpp include include include using namespace std; int n, m, h[2005][2005], l[2005][2005], r[2005][2005], uu, iii=0, jjj=0; bool a[2005][2005]; void
阅读全文
摘要:悬线法 cpp include include include using namespace std; int n, m, ans=0, h[1005][1005], l[1005][1005], r[1005][1005]; bool a[1005][1005]; char s[15]; int
阅读全文
摘要:建议看看 "王知昆dalao的论文" ,讲得很好 cpp include include include include using namespace std; int l, w, n, ans=0, sh, xi, ma; struct Node{ int x, y; }nd[5105]; bo
阅读全文
摘要:```cpp include include include using namespace std; int n, x; double a[55][55]; const double eps=1e 7; void gauss(){ for(int i=1; ia[maxi][i]) maxi =
阅读全文
摘要:```cpp include include include include using namespace std; int n, x; double a[105][105]; bool gauss(){ for(int i=1; ifabs(a[maxi][i])) maxi = j; if(f
阅读全文
摘要:upd:现在推荐使用一个长度为 $n$ 的一维向量。若状态矩阵 $F$ 对下一时间的状态矩阵 $F'$ 有影响,则 $F'=FA$ 中的 转移矩阵 $A$ 的赋值方法是: 若状态矩阵中的第 $x$ 个数对下一单位时间的状态矩阵的第 $y$ 个数有影响,则将转移矩阵的第 $x$ 行第 $y$ 列赋值为
阅读全文
摘要:```cpp include include using namespace std; typedef long long ll; ll k; const ll mod=1e9+7; struct Matrix{ int n; ll num[105][105]; Matrix operator (c
阅读全文
摘要:学习建图 cpp include include include using namespace std; int n, m, hea[2005], cnt, scc, ind, dfn[2005], loo[2005], bel[2005]; int uu, vv, ww, sta[2005],
阅读全文
摘要:不用topsort的,我也不知道为啥。 cpp include include include using namespace std; struct Node{ int fro, too; }nd[2005]; struct Edge{ int too, nxt, val; }edge[40000
阅读全文
摘要:我们想,倘若有两个曲线u v,他们不能共存,那么连边一定是: u v' u' v v' u v u' 其中x代表x边在内侧(外侧),x'代表x边在外侧(内侧) cpp include include include using namespace std; int n, m, dfn[1005],
阅读全文
摘要:2 SAT裸题 如果选u则必选v', 如果选v则必选u',连边即可。 cpp include include include using namespace std; struct Edge{ int too, nxt; }edge[40005]; int n, m, uu, vv, hea[160
阅读全文
摘要:搞上一棵AC自动机,想让它无限匹配,dfs找环即可 cpp include include include include using namespace std; int n, len; char a[30005]; queue d; bool vis[30005], tmp[30005]; st
阅读全文
摘要:蒟蒻也能写出来的AC代码!这题是AC自动机模板题。插入单词时用一个没出现过的字符隔开就行了。 一些细节请看注释 cpp include include include include using namespace std; char a[1000005], b[1000205];//b数组要开这么
阅读全文
摘要:纪念一下我一晚上写了八遍AC自动机 这是加强版的: cpp include include include include using namespace std; int n, cnt[155], mp[155], len, maxn; char a[155][75], b[1000005]; q
阅读全文
摘要:treap求中位数。 cpp include include include using namespace std; typedef long long ll; int n, m, rot, siz, uu, vv; ll h[1005], all, num, tmp, ans[1005][100
阅读全文
摘要:并查集+treap维护的第k 大 数 cpp include include include using namespace std; struct Node{ int val, l, r, rnd, sze, hav; }nd[200005]; int n, m, fa[200005], hmn[
阅读全文
摘要:treap做法,参考 "hzwer的博客" splay做法,参照 "zyf2000" ,但是一般我们用splay都是维护区间的
阅读全文
摘要:模板题 cpp include include using namespace std; struct Edge{ int too, nxt; }edge[200005]; int n, m, dfn[100005], loo[100005], ind, uu, vv, cnt, hea[10000
阅读全文
摘要:K短路裸题。
阅读全文
摘要:```cpp include include include include using namespace std; typedef unsigned long long ull; struct Node{ ull val1, val2; }node[10005]; char a[1505]; i
阅读全文
摘要:注意:如果是这么个写法,堆数组要开成n+m的。 为什么呢?设想一下从1到2有m条长度递减的路,这岂不是要入队m次…… cpp include include include include using namespace std; struct Edge{ int too, nxt, val; }e
阅读全文
摘要:```cpp include include include include using namespace std; int n, m, s, dis[10005], din, uu, vv, ww, hea[10005], cnt; bool vis[10005]; struct Node{ i
阅读全文
摘要:在考场上我们可以打表发现规律是 $ ab a b $ 。下面给出证明(看的网上的)。 若有正数 $ x $ 不能被 $ a $ , $ b $ 组合出,假设 $ a b $ ,则存在 $$ x=ap+bq=a(p b)+b(q+a) $$ 其中 $ p 0, q0 $ 。 为什么呢?如果学过exgc
阅读全文
摘要:1日 luogu 2627 luogu 2951 NOIP2017D1T1 luogu 1262 luogu 2863 2日 luogu 2865 3日 luogu 2901 poj 2449 4日 luogu 3388 luogu 3369 poj 2985 vijos 1459 5日 luogu
阅读全文
摘要:设dp[i]表示i位置不选且i之前的都合法的最小损失值。 cpp include include include using namespace std; typedef long long ll; //dp[i] = min{dp[j]} + w[i] | i j i k 1 n k; for(i
阅读全文

浙公网安备 33010602011771号