随笔分类 - 模板
摘要:#include using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const int MAXN = 5e5 + 100; const int MAXM = 3e3 + 10; template inline void read(T &x) { x = 0; T ff = 1, ch =...
阅读全文
摘要:#include using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const int MAXN = 1e7 + 100; const int MAXM = 3e3 + 10; inline int read() { int x = 0, ff = 1; char ch = getchar...
阅读全文
摘要:最短路,即第1短路有很多种求法,SPFA,Dijkstra等,但第k短路怎么求呢?其实也是基于Dijkstra;因为Dijkstra用的是堆优化,这样保证每次弹出来的都是最小值,只是求最短路只是弹出一次就返回了,我们可以用Dijkstra弹出k个距离后再返回,这样根据弹出的先后顺序能够求出1~k短路
阅读全文
摘要:#include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long inline int read() { int x = 0,ff = 1; char ch = ge...
阅读全文
摘要:#include using namespace std; inline int read() { int x = 0,ff = 1; char ch = getchar(); while(!isdigit(ch)) { if(ch == '-') ff = -1; ch = getchar(); } while(isdig...
阅读全文
摘要:#include using namespace std; #define ll long long #define INF 0x3f3f3f3f #define MAXN 300010 #define MAXM 3010 #define _ 0 inline int read() { int x = 0,ff = 1, ch = getchar(); while(!i...
阅读全文
摘要:给出一道例题 poj2823 我们知道,在暴力枚举的过程中,有一个地方是重复比较了,就是在找当前的f(i)的时候,i的前面其它m-1个数在算f(i-1)的时候我们就比较过了。当你一个个往下找时,每一次都是少一个然后多一个,如果少的不是最大值,然后再问新加进来的,看起来很省时间对吧,那么如果少了的是最
阅读全文
摘要:题目描述 给出一个序列a, 求a的最长上升子序列 输入输出格式 输入格式: 第一行是一个数n, 接下来一行,每行为n个数 输出格式: 一个数,即最长上升子序列的长度 朴素版的lis是O(N ^ 2)的做法,这里就不在给出;当数据大时很容易被卡,通过二分优化 + 贪心可以优化成为O(NlogN),首先
阅读全文
摘要:题目描述 小C最近学了很多最小生成树的算法,Prim算法、Kurskal算法、消圈算法等等。正当小C洋洋得意之时,小P又来泼小C冷水了。小P说,让小C求出一个无向图的次小生成树,而且这个次小生成树还得是严格次小的,也就是说:如果最小生成树选择的边集是EM,严格次小生成树选择的边集是ES,那么需要满足
阅读全文
摘要:#include using namespace std; #define INF 0x3f3f3f3f #define MAXN 1000010 #define MAXM 5010 inline int read() { int x = 0,ff = 1;char ch = getchar(); while(!isdigit(ch)) { if...
阅读全文
摘要:#include using namespace std; #define INF 0x3f3f3f3f #define MAXN 1000010 #define MAXM 5010 inline int read() { int x = 0,ff = 1;char ch = getchar(); while(!isdigit(ch)) { if...
阅读全文
摘要:#include using namespace std; #define INF 0x3f3f3f3f #define MAXN 100010 #define MAXM 5010 inline int read() { int x = 0,ff = 1;char ch = getchar(); while(!isdigit(ch)) { if(...
阅读全文
摘要:#include using namespace std; #define INF 0x3f3f3f3f #define MAXN 1000010 #define MAXM 5010 inline int read() { int x = 0,ff = 1;char ch = getchar(); while(!isdigit(ch)) { if...
阅读全文
摘要:#include using namespace std; #define INF 0x3f3f3f3f #define MAXN 1000010 #define MAXM 5010 inline int read() { int x = 0,ff = 1;char ch = getchar(); while(!isdigit(ch)) { if(...
阅读全文