摘要: #include<iostream> #include<cstring> using namespace std; const int N=510,M=10010; struct Edge{ int a; int b; int w; }e[M];//把每个边保存下来即可 int dist[N]; i 阅读全文
posted @ 2020-11-06 21:05 Swelsh-corgi 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 题意:在一张节点带有权值(点权)的图上找出一条从1到n的路径,使路径上能选出两个点p,q(先经过p在经过q),并且“节点q的权值减去p的权值”最大。 思路: 1. 枚举每一个节点 i ,1 ~ i 按照最短路来求,记录1 ~ i 中最短的边是 dim [ i ]. 2. 反向建图,枚举每一个节点 i 阅读全文
posted @ 2020-11-06 20:09 Swelsh-corgi 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 没太想明白(就当存在模板吧) #include<bits/stdc++.h> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <algorithm> #include <queue> 阅读全文
posted @ 2020-11-05 20:33 Swelsh-corgi 阅读(68) 评论(0) 推荐(0) 编辑
摘要: 次短路模板 #include <bits/stdc++.h> #include <cstring> #include <queue> using namespace std; const int N = 5005, M = 2e5 + 5; int n,m,u,v,w; struct Edge{ i 阅读全文
posted @ 2020-11-05 20:31 Swelsh-corgi 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 题意:0代表没有炸弹,1代表有炸弹,点燃一个炸弹可以引起连锁反应,花费是a,可以在没没有炸弹的地方添加炸弹,花费为吧,然后构成连续的炸弹,引起连锁反应。 思路:统计每段连续的1的起始位置和结束位置。然后相邻的两段的1中间的0的个数为 ans ,如果 b * ans < = a, 说明填炸弹更划算,如 阅读全文
posted @ 2020-11-03 20:04 Swelsh-corgi 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 题意:统计从1号点到所有的点的最短路的条数。 思路:权重都是1,开一个数组cnt [ N ], cnt[ i ]代表到 i 的最短路的个数。 如果dis[ v ] > dis[ u ] + 1,那么到 v 的最短路的个数也就是到 u 的个数( cnt [ v ]=cnt[ u ])。 dis[ v 阅读全文
posted @ 2020-10-29 20:44 Swelsh-corgi 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 题意: 拓扑排序,输出字典序最小的。 思路:优先队列优化。 #include <iostream> #include <vector> #include <queue> #include<string.h> using namespace std; int n, m; const int N=1e5 阅读全文
posted @ 2020-10-28 19:52 Swelsh-corgi 阅读(416) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> #include <vector> #include <queue> using namespace std; int n, m; const int N=1e5+10; vector<int> out[N]; //入度记录 int in[N]; //出度记录 阅读全文
posted @ 2020-10-28 19:25 Swelsh-corgi 阅读(91) 评论(0) 推荐(0) 编辑
摘要: 思路:既然求最大生成树,那就把虽有的边的权重都变成负的,这样就能求得最大生成树了,然后来一个ans更新,每次比较边的大小就能找到最大边中的最小边了。 #include<stdio.h> #include<string.h> #include <iostream> #define MAX 0x3f3f 阅读全文
posted @ 2020-10-24 16:59 Swelsh-corgi 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 最小生成树模板。 #include <iostream> #include<stdio.h> #include<string.h> #define MAX 0x3f3f3f3f using namespace std; int vis[1010]; int Map[1010][1010]; int 阅读全文
posted @ 2020-10-24 16:10 Swelsh-corgi 阅读(105) 评论(0) 推荐(0) 编辑