摘要: 给出一个无向连通图,问加入边的过程中,桥的个数。 先用tarjan算法求出桥的总数,标记每个桥的终点。 每加入两个顶点,就查询两个顶点的lca,把lca路径上的桥都剪掉~ 链式前向星: #include<cstdio> #include<algorithm> #include<vector> #in 阅读全文
posted @ 2020-02-15 19:59 zlc0405 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 割点的概念:对于无向图,删除这个点与其相连的边,整个图的连通分量个数增加。 对于无向图的tarjan算法,必须要设前驱~ 求割点的模板~ #include<cstdio> #include<algorithm> #include<vector> #include<stack> #include<cs 阅读全文
posted @ 2020-02-15 19:35 zlc0405 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 解决两个问题,对于给定的有向图,需要给多少个点可以遍历整个图,需要加多少条边可以使整个图变得强连通~ 思路:用tarjan进行缩点,得到一个scc图,算出有n个入度为0的点,m个出度为0的点,第一个答案就是n,第二个答案就是max(n,m) 链式前向星版本: #include<cstdio> #in 阅读全文
posted @ 2020-02-15 19:23 zlc0405 阅读(137) 评论(0) 推荐(0) 编辑
摘要: DFS+剪枝~ #include<bits/stdc++.h> using namespace std; int a[30][4]; int N; int cnt; int c[30]; int p[30]; unordered_map<long long,int> pos; bool dfs (i 阅读全文
posted @ 2020-02-15 12:30 zlc0405 阅读(157) 评论(0) 推荐(0) 编辑
摘要: #include<bits/stdc++.h> using namespace std; int main() { double i; double k; for(i=0.000;i-2.000<=0.00000001;i+=0.001) { k=1; double sum=1+(1-i)/(2*1 阅读全文
posted @ 2020-02-15 12:09 zlc0405 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 简单模拟~ #include<bits/stdc++.h> using namespace std; const int maxn=1e6+14; int a[maxn]; unordered_map<char,int> pos; string s="_abcdefghijklmnopqrstuvw 阅读全文
posted @ 2020-02-15 12:04 zlc0405 阅读(95) 评论(0) 推荐(0) 编辑
摘要: 题意:有两个容量互质的容器,需要用这两个容器量出目标重量的水,找到其中一组解。bfs,使得搜索得到的解是步数最少的,遍历前驱法输出路径~ #include<bits/stdc++.h> using namespace std; const int maxn=1e6+14; struct node { 阅读全文
posted @ 2020-02-15 11:56 zlc0405 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 题目大意:规定 i 为入栈,o 为出栈,现在给两个字符串st1,st2,现在要将st1转化为st2,转化方法是,st1中字符从头开始入栈,并合理出栈构造出st2。请输出所有可能的出入栈步骤。 深度优先搜索+回溯~ #include<bits/stdc++.h> using namespace std 阅读全文
posted @ 2020-02-15 11:09 zlc0405 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 建立结构体保存每个结点的前驱,操作符,来回两遍拓扑排序~ #include<bits/stdc++.h> using namespace std; const int maxn=50014; struct node { vector<int> pre; double data; int fuhao= 阅读全文
posted @ 2020-02-14 22:07 zlc0405 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 删除字符的镜像问题,状态转移方程一样~ #include<bits/stdc++.h> using namespace std; const int maxn=1014; const int mod=1e9+7; string s; long long dp[maxn][maxn]; int mai 阅读全文
posted @ 2020-02-14 21:34 zlc0405 阅读(154) 评论(0) 推荐(0) 编辑