08 2017 档案
摘要:1 /* 2 网络流之最大流Dinic算法模版 3 */ 4 #include 5 #include 6 #include 7 using namespace std; 8 const int maxn = 205; 9 const int inf = 0x3f3f3f3f; 10 struct 11 { 12 int c,f;//c为边的容量,f为边的容量 1...
阅读全文
摘要:1 /* 2 网络流的最大流问题 3 刚学习Dinic算法。模版题 4 */ 5 #include 6 #include 7 #include 8 using namespace std; 9 const int maxn = 205; 10 const int inf = 0x3f3f3f3f; 11 struct 12 { 13 int c,f; 14 }e...
阅读全文
摘要:1 /* 2 归并排序模版 3 对n个数进行排序 4 时间复杂度:O(nlogn); 5 利用分治思想,对比左半边和右边边放入一个暂时的数组进行排序 6 */ 7 #include 8 using namespace std; 9 const int maxn = 1005; 10 int a[maxn], t[maxn]; 11 void merge(int a[], i...
阅读全文
摘要:1 /* 2 快速幂模版 3 求x^t%mod 4 时间复杂度:O(logn) 5 注:递归可能爆栈 6 原理:x^t = (x^(t/2))^2 + x^(n%2); 7 */ 8 #include 9 using namespace std; 10 long long quick_pow(long long x, long long t, long long mod) 1...
阅读全文
摘要:1 /* 2 匈牙利算法模版邻接表版 3 最大匹配问题 4 时间复杂度:O (nm) 5 */ 6 #include 7 #include 8 #include 9 using namespace std; 10 const int maxn = 505; 11 vector v[maxn];//x = v[i][j]表示i可以与x匹配 12 int vis[maxn],...
阅读全文
摘要:1 //匈牙利算法模版题 2 #include 3 #include 4 #include 5 using namespace std; 6 const int maxn = 505; 7 vector v[maxn]; 8 int vis[maxn],match[maxn]; 9 bool dfs(int t) 10 { 11 for(int i = 0; i ...
阅读全文
摘要:1 /* 2 匈牙利算法模版题 3 邻接表实现,邻接矩阵超时 4 最大匹配问题 5 */ 6 #include 7 #include 8 #include 9 using namespace std; 10 const int maxn = 505; 11 vector v[maxn];//x = v[i][j]表示i可以与x进行匹配 12 int vis[maxn],...
阅读全文
摘要:1 //裸拓扑排序,注意先输出比较小的数,使用优先队列即可 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 const int maxn = 505; 9 vector v[maxn]; 10 priority_queue q; 11 int f[maxn]...
阅读全文
摘要:1 //线段树入门,单点修改,区间查询 2 #include 3 const int maxn = 3*1e6+5; 4 struct node 5 { 6 int l,r; 7 node *pl, *pr; 8 int s; 9 }; 10 node t[maxn]; 11 int cnt = 0; 12 int mid(node *p) 13 { ...
阅读全文
摘要:1 //tarjan裸题 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int maxn = 1e4+5; 8 stack s; 9 vector v[maxn]; 10 int dfn[maxn],low[maxn],ins[maxn]; 11 int ant,cn...
阅读全文
摘要:1 /* 2 最短路径问题 3 可利用Bellman-Ford算法或者Dijktra算法求解。 4 */ 5 #include 6 #include 7 #include 8 #include 9 using namespace std; 10 const int maxn = 205; 11 const int inf = 0x3f3f3f3f...
阅读全文
摘要:1 /* 2 题意让你求交换次序,实际求逆序对数即可 3 而归并排序时,刚好需要比较mid两边的数,所以只需在归并时累加即可 4 5 例:(归并时一定会排好小组内的顺序) 6 7 对应位置: i m j 8 对应数字: 4 5 6 1 2 3 9 10 4 > 1 -> ans += 3;//因为4为前半最小值,则前半部分所有元素符合要求(ans += m...
阅读全文
摘要:1 /* 2 排序 之 归并排序 3 T(n) = O(nlogn) 4 通过分治思想,将数组不断二分 5 最后通过合并两组数据(合并数据时间复杂度为O(n))递归实现排序 6 不论什么情况,时间复杂度都为O(nlogn) 7 但是注意付出了开辟空间(t[maxn])的代价 8 */ 9 #include 10 using namespace std; 11 const i...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 const int maxn = 105; 5 int s[maxn];//s[i]表示每行前i个数的和 6 int d[maxn];//d[i]表示每行取i个数时的最大价值 7 int f[10005];//限制数量为k个,往f中背,记录最大价值 8 int n,m,k; 9 i...
阅读全文
摘要:1 //典型的多重背包 2 #include 3 #include 4 using namespace std; 5 int d[1005]; 6 int n,m; 7 void zb(int r,int v) 8 { 9 for(int i = n; i >= r; --i) 10 if(d[i-r] + v > d[i]) 11 ...
阅读全文
摘要:1 /* 2 注意两点 3 1. 不可以使用替换可用节点为不可用节点的方法进行DFS 4 因为角落也可能有油,替换了就出不来。(某学长指导) 5 2. 可用通过开一个数组(例如我的b[][]数组) 6 用了存储到当前位置剩余最大油量 7 这样到话,下次若有更优解,则更新b 8 反之无需继续遍历 9 对于BFS,可用结构体记录坐标和到当前位置到剩余...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 int a[1005]; 7 int min(int x, int y) 8 { 9 return x > t; 15 while (t--) 16 { 17 cin >> n; 18 ...
阅读全文

浙公网安备 33010602011771号