随笔分类 - 算法初级
摘要:#include <bits/stdc++.h> using namespace std; const int N = 100010, M = 1000010; int ne[N]; char s[M], p[N]; int n, m; int main() { cin >> n >> p + 1
阅读全文
摘要:方法一:记忆化dfs class Solution { boolean[][] visited; public boolean containsCycle(char[][] grid) { int m = grid.length, n = grid[0].length; visited = new
阅读全文
摘要:分析:先按照w+s排序,从前到后遍历即可 #include <bits/stdc++.h> using namespace std; const int N = 50050; typedef pair<int,int> PII; PII f[N]; int n; int main() { scanf
阅读全文
摘要:分析:先按区间左端点进行排序,然后遍历区间,找一个区间左右端点覆盖起始点,右端点尽量远,直到可以覆盖目标区间右端点 #include <bits/stdc++.h> using namespace std; const int N = 100010; struct Edge{int a, b;} e
阅读全文
摘要:分析:先将区间按左端点排序,然后建一个小堆存放以有组的右端点,然后遍历区间,当堆为空或堆中最小的右端点都大于当前区间的左端点, 则当前区间另分一组,否则就将当前区间划分给堆中最小左端点的那个区间,并更新这个区间的右端点,最后返回堆的大小 #include <bits/stdc++.h> using
阅读全文
摘要:分析:先按区间的右端点排序,然后从左到右遍历,当前区间左端点小于上一区间的右端点,总个数不变,否则总个数加一,并更新右端点 #include <bits/stdc++.h> using namespace std; const int N = 100010; struct Edge{int a, b
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 6060; int h[N], e[N], ne[N],idx; int w[N], f[N][2]; bool hasF[N]; int n; void add(int a, i
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 550, M = 100010; int h[N], e[M], ne[M], idx; int match[N]; bool st[N]; int n1, n2, m; void
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 100010; int h[N], e[N], ne[N], w[N], idx; int color[N]; int n, m; void add(int a, int b, i
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 200020; int p[N]; int n, m; struct Edge { int a, b, w; bool operator< (const Edge &W) cons
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 550, M = 100010, INF = 0x3f3f3f3f; int g[N][N], dist[N]; // dist存点到(最小生成树的点集合)的最小距离 bool s
阅读全文
摘要:分析: f[i, j, k]表示从i走到j的路径上除i和j点外只经过1到k的点的所有路径的最短距离。那么f[i, j, k] = min(f[i, j, k - 1), f[i, k, k - 1] + f[k, j, k - 1]。 因此在计算第k层的f[i, j]的时候必须先将第k - 1层的所
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 10010; int h[N], e[N], ne[N], w[N], idx; int dist[N], cnt[N]; bool st[N]; int n, m; void a
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 100010; int h[N], e[N], w[N], ne[N], idx; int dist[N]; bool st[N]; int m, n; void add(int
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 550, M = 10010; struct Edges{int a, b, w;}edges[M]; int dist[N], pre[N]; int m, n, k; int
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 1000010; int h[N], e[N], ne[N], w[N], idx; int dist[N]; bool st[N]; int m, n; void add(int
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 550, M = 10010; int g[N][N], dist[N]; bool st[N]; int m, n; int dijkstra() { memset(dist,0
阅读全文
摘要:#include <iostream> using namespace std; int main() { int a, b , p; cin >> a >> b >> p; int res = 1 % p; while(b) { if(b&1) res = res * 1ll * a % p; a
阅读全文

浙公网安备 33010602011771号