随笔分类 - 模板
摘要:~~~ include include include using namespace std; typedef long long ll; const int maxn=100010; int n,m; struct SegmentTree { int l,r; ll sum,lazy;//区间和
阅读全文
摘要:缩点 Tarjan模板 dfs过程的每条边x→y 树枝边(在搜索树中的边,y从未访问过),那么递归处理y;low[x]=min(low[x],low[y]) 后向边(y被访问过,且在栈中),low[x]=min(low[x],dfn[y]) 横叉边(y被访问过,但不在栈中),什么也不做 对不同强连通
阅读全文
摘要:高斯消元模板 要求输出解的情况(无穷解/无解) 1. 之前写的丑陋代码 ~~~ include include include include using namespace std; const double eps=1e 7; const int maxn=1000; int n;//n个变量
阅读全文
摘要:1 #include 2 using namespace std; 3 #define key1 first 4 #define key2 second 5 const int size=2048,p1=131,p2=13331; 6 const int mod1=1e6+3,mod2=1e6+33;//两个大质数 双hash 7 int n,ans; 8 char tmp[s...
阅读全文
摘要:1 #include 2 using namespace std; 3 vector q; 4 int n,opt,x; 5 int main() 6 { 7 scanf("%d",&n); 8 while(n--) 9 { 10 scanf("%d%d",&opt,&x); 11 switch(opt) 12 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=1005; 4 const int maxm=3005; 5 struct edge{int to,nex;}e[maxm]; 6 int head[maxn],tot; 7 int deep[maxn],f[maxn][30]; 8 int T,n,m,q; 9 inline...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=5005; 4 const int maxm=200005; 5 struct node{ 6 int cnt,fa; 7 }f[maxn]; 8 inline void read(int &tmp) 9 { 10 int x=1;char c=getchar(...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=5005; 4 const int INF=0x3f3f3f3f; 5 inline void read(int &tmp) 6 { 7 int x=1;char c=getchar(); 8 for(tmp=0;!isdigit(c);c=getchar()) ...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=500005; 4 inline void read(int &tmp) 5 { 6 int x=1;char c=getchar(); 7 for(tmp=0;!isdigit(c);c=getchar()) if(c=='-') x=-1; 8 for...
阅读全文
摘要:1 /* 2 并查集(树实现) 3 路径压缩、按秩合并 4 使用前调用init() 5 find(x) 查找x的根节点(路径压缩) 6 Union(x,y) 启发式合并 7 */ 8 #include 9 using namespace std; 10 const int size=100005;//集合大小 11 int n,m;//n--元素个数 m--查询次数 1...
阅读全文
摘要:1 ////KMP模式匹配 2 ////a、b字符串下标均从1开始 3 #include 4 using namespace std; 5 const int maxn=1000005; 6 int lena,lenb; 7 char a[maxn],b[maxn]; 8 int Next[maxn];//注意这里为int 9 inline void init()//预...
阅读全文
摘要:1 #include 2 using namespace std; 3 int n; 4 long long a[500005],b[500005],ans;//a为待排序数组,b为临时数组,ans为逆序对数 5 void mergesort(int l,int r)//l为左边界,r为右边界 6 { 7 if(l==r) return; 8 int mid=...
阅读全文
摘要:1 #include 2 using namespace std; 3 long long a,b,p; 4 long long mul(long long a,long long b,long long p) 5 { 6 long long ans=0; 7 while(b) 8 { 9 if(b&1) ans=(ans+a)%p; 1...
阅读全文
摘要:1 #include 2 using namespace std; 3 long long a,b,p; 4 long long quickpow(long long a,long long b,long long p) 5 { 6 long long ans=1; 7 while(b) 8 { 9 if(b&1) ans=ans%p*a...
阅读全文
摘要:1 #include 2 using namespace std; 3 const double eps=0.0000001;//精度 4 struct f{ 5 double s[20]; 6 int n; 7 inline double calc(double x) 8 { 9 double sum=0; 10 ...
阅读全文
摘要:1 /* 2 高精度进制加法 3 n为进制(n 6 using namespace std; 7 const int maxn=10000; 8 int n; 9 struct bign{ 10 int d[maxn],len; 11 inline bign(){len=1;memset(d,0,sizeof(d));} 12 inline ...
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn=10000;//最大处理位数 4 struct bign 5 { 6 int d[maxn],len; //下标从0开始 7 inline void clean() {while(len>1&&!d[len-1]) len--;}; //删除前导0 ...
阅读全文
摘要:1 /* 2 高精度减法 3 洛谷极端数据 最大位数开到100000 4 若被减数小于减数 输出负号后交换减数与被减数 5 结构体初始化 6 定义去除前导0函数 7 重载赋值符号 减号 小于号(用于比较大小) 8 定义字符串输出函数 9 重载输入输出流 10 */ 11 #include 12 using ...
阅读全文
摘要:1 /* 2 高精度乘法(无负数) 3 结构体初始化 4 定义去除前导0函数 5 重载赋值符号、乘号 6 定义字符串输出函数 7 重载输入输出 8 */ 9 #include 10 using namespace std; 11 const int maxn=10000; 12 struct bign{ 13 int ...
阅读全文