摘要: ###1.dijkstra 时间复杂度:O(n^2) n次迭代,每次找到距离集合S最短的点 每次迭代要用找到的点t来更新其他点到S的最短距离。 #include<iostream> #include<algorithm> #include<cstring> using namespace std; 阅读全文
posted @ 2020-09-18 19:27 30天CF上蓝!!! 阅读(148) 评论(0) 推荐(0) 编辑
摘要: ###1.y氏写法 链式前向星注意事项,如果a->b,b->c在前向星中a的临点只有b,所以在求连通块的数量的时候不能一次dfs,要多次dfs! const int N=?,M=??;//N是点数,M是边数 int h[N],e[M],ne[M],idx; void add(int a,int b, 阅读全文
posted @ 2020-09-18 19:06 30天CF上蓝!!! 阅读(170) 评论(0) 推荐(0) 编辑
摘要: acwing836—合并集合 #include<iostream> #include<cstdio> using namespace std; const int N=1e5+10; int n,m; int p[N]; int find(int x)//返回x的祖宗节点 { if(x!=p[x]) 阅读全文
posted @ 2020-09-17 15:01 30天CF上蓝!!! 阅读(119) 评论(0) 推荐(0) 编辑
摘要: ll f(ll q,ll n)//递归求快速幂 { if(n==1)return q; if(n&1) return q*f(q,n-1); else return f(q,n/2)*f(q,n/2); } #include<bits/stdc++.h> using namespace std; t 阅读全文
posted @ 2020-09-14 19:27 30天CF上蓝!!! 阅读(307) 评论(0) 推荐(0) 编辑
摘要: ###Dilworth定理 导弹拦截系统](https://www.acwing.com/problem/content/1012/) 这个定理和一个对偶定理,讲的意思大概就是,给一个偏序关系,比如说是一个数它出现的位置i在另一个数出现的位置j之前,而且满足ai>aj.那么满足这个偏序关系的链就叫做 阅读全文
posted @ 2020-09-14 14:54 30天CF上蓝!!! 阅读(139) 评论(0) 推荐(0) 编辑
摘要: ###1. #ifdef 标识符 代码段1 #else 代码段2(可以为空) #endif (条件编译结束语句,和#ifdef配套使用) 如果标识符被#define过,则编译代码段1,否则编译代码段2 ###2. #ifndef 标识符 代码段1 #else 代码段2(可以为空) #endif (条 阅读全文
posted @ 2020-09-08 18:10 30天CF上蓝!!! 阅读(223) 评论(0) 推荐(0) 编辑
摘要: 水题链接 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=1e3+10; int n; class stu { public: int idx; int Ch; int 阅读全文
posted @ 2020-07-22 01:28 30天CF上蓝!!! 阅读(331) 评论(0) 推荐(0) 编辑
摘要: C/C++ 四种清空输入缓冲区的方法 比较实用的一种 char c; while(c=getchar()!='\n'); 或者是这种 cin.ignore(count,c); count代表要清除的字符的长度,c代表某个字符 一般把count设的大一些 例如cin.ignore(1000,'\n') 阅读全文
posted @ 2020-07-22 01:24 30天CF上蓝!!! 阅读(880) 评论(0) 推荐(0) 编辑
摘要: 题目链接:第k个数 题意:求n个数中第k小的数 ####题解: //由快速排序算法演变而来的快速选择算法 #include<iostream> using namespace std; const int N=1e5+10; int a[N]; //k是整个区间中的第k小的数。 void quick 阅读全文
posted @ 2020-07-21 08:24 30天CF上蓝!!! 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 1.\(对于一个足够大的整数N,不超过N的质数大约有N/lnN个,即每lnN个数中大约有1个质数.\) 2.\(约数总是成对出现的,如果M|N,则\frac{N}{M}|N.\) 试除法判定质数 bool is_prime(int n) { for(int i=2;i<=n/i;i++) if(n% 阅读全文
posted @ 2020-07-10 17:22 30天CF上蓝!!! 阅读(145) 评论(0) 推荐(0) 编辑