
模板
KEMNHan
希望工作955,管吃住,生活设施齐全,有零食,小姐姐多,写不出bug
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
c++大数重载模板
#include <bits/stdc++.h> using namespace std; const int MAXN=9999,MAXSIZE=1000,DLEN=4; class BigNum { private: int a[MAXSIZE]; //可以控制大数的位数 int len; //大数长度 public: BigNum() ...原创 2018-08-01 09:25:52 · 329 阅读 · 0 评论 -
c++大数模板(分块)
高精度加法 (string + string) const int L=1005; 大数长度 string add(string a,string b)//只限两个非负整数相加 { string ans; int na[L]={0},nb[L]={0}; int la=a.size(),lb=b.size(); for(int i=...原创 2019-04-15 12:50:57 · 313 阅读 · 0 评论 -
斐波那契第n项,快速幂,玄学算法
斐波那契快速幂 下面的神仙代码的构造矩阵是 | 1 0 | | 0 1 | 留着用来当模板。 #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; const int mod=1e9+7; pll operator *(const...原创 2019-07-08 11:20:40 · 305 阅读 · 0 评论 -
线段树 | 单点,区间更新(set,add) | 区间最大值,最小值,区间和
#include <bits/stdc++.h> using namespace std; typedef long long LL; const LL Inf=1LL<<62; const int maxn=1e5+5; int T,n,m; struct segement_tree { struct node { int l,r; ...原创 2019-07-19 21:01:25 · 188 阅读 · 0 评论 -
ST和RMQ 区间最值
ST(Sparse Table)和 RMQ(Range Minimum/Maximum Query) 对于长度为n的数列A,回答若干次询问RMQ(i,j),返回数列A中下标在区间[i,j]中的最小/大值。一般我们用ST算法解决这样的问题。ST(Sparse Table)算法可以在O(nlogn)时间内进行预处理,然后在O(1)时间内回答每个查询。 板子: void st(int n) {...原创 2019-07-31 10:38:46 · 129 阅读 · 0 评论 -
牛客多校 generator 1
题意:求fn的第1e10e6项,用广义欧拉降幂了半天都wa,后来才知道时十进制快速幂,nnd第一次知道这玩意 构造矩阵: |a,b| |1,0| 然后跑一下十进制快速幂就好了 #include<bits/stdc++.h> using namespace std; typedef long long ll; #define mp make_pair ty...原创 2019-08-02 13:21:09 · 217 阅读 · 0 评论 -
十进制快速幂 模板
ll pow ( ll a, ll b, ll n ) { while(n) { if(n&1) b=b*a; a=a*a; n>>=1; } return b; } ll tenpow() { int len=s.size()-1; ll res=a,base=1; ...原创 2019-08-02 14:17:09 · 210 阅读 · 0 评论 -
Miller_rabin板子 快速判断是否素数
板子,除了这个算法不保证一定正确,效率很高,错误率很低可以忽略不记 如果用这个板子出现了wa而不是tle的时候,可以适当增加_time的次数 const int _time=5; ll multi(ll a, ll b, ll mod) { ll ret = 0; while(b) { if(b & 1) ret = ret + a; ...原创 2019-08-22 15:03:58 · 201 阅读 · 0 评论 -
主席树板子(静态,区间第k大,小)
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, x, y, k; class zhuxishu { private: int a[N], cnt, root[N]; vector<int>v; struct node { ...原创 2019-08-27 16:16:42 · 185 阅读 · 0 评论 -
Dijkstra模板 最短路最小花费
struct dij { int n; const int inf = 0x3f3f3f3f; int maps[maxn][maxn]; int d[maxn], v[maxn]; int Dijkstra(int s, int t) { memset(d, inf, sizeof d); memset(v, 0,...原创 2019-08-30 15:09:58 · 191 阅读 · 0 评论 -
最长公共子序列&&最长公共子串 模板 LCS
最长公共子序列 int lcs(char a[],char b[]) { int i , j , k , w , ans , l , r , mid ; for( i = 0 ; i < 26 ; i++) location[i].clear() ; for( i = strlen(b)-1 ; i >= 0 ; i--) location[b[i]...原创 2019-08-30 15:26:00 · 260 阅读 · 0 评论 -
BM求线性递推 快速推线性数列第n项
BM模板(杜教版): #include<bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long ll; typedef vector<long long> VL; const ll mod = 998244353; ll powmod(ll a, ll b)...原创 2019-09-09 13:19:07 · 223 阅读 · 0 评论 -
读入挂模板 常用
inline int read() { char ch = getchar(); int x = 0, f = 1; while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();} while('0' <= ch && ch <= '9') {x = x * 1...原创 2019-04-07 13:19:59 · 190 阅读 · 0 评论 -
线性筛总结(素数,欧拉函数,莫比乌斯函数,约数个数)
素数筛 int vis[maxn],pri[maxn]; void init() { for(int i=2;i<=maxn;i++) { if(!vis[i]) pri[++pri[0]]=i; for(int j=1;j<=pri[0]&&i*pri[j]<=maxn;j++) ...原创 2019-03-08 12:39:13 · 168 阅读 · 0 评论 -
dfs&bfs模板
DFS: 深度优先搜索从最开始的状态出发,遍历所有可以达到的状态。由此可以对所有的状态进行操作或者列出所有的状态。 模板: //建立搜索区间 char map[][]; void dfs(int x,int y) { //对此节点的操作 //根据题目要求判断其他点 for(int i = ; i < ; i++) if(符合条件) ...原创 2019-01-27 12:33:58 · 167 阅读 · 0 评论 -
java BigInteger 大数运算
java大数运算方便,但是某些时间卡的比较厉害的题会超时23333 将普通数值转换为大数 java.math.BigInteger//大数运算库 BigInteger a=BigInteger.valueOf(/*数字*/); 大数运算 操作 BigInteger abs() //返回大整数的绝对值 BigInteger add(BigInteger val) //返回两个大整数...原创 2018-08-01 09:36:02 · 1267 阅读 · 0 评论 -
线段树单点|区间更新模板
#include<bits/stdc++.h> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define inf 0x3f3f3f3f typedef long long ll; const int maxn=50010; int a[maxn],ans[maxn],lazy[maxn]; void pu...原创 2018-08-10 13:22:25 · 216 阅读 · 0 评论 -
手写sqrt 牛顿迭代法
牛顿迭代法: x^2 = a的解,也就是函数f(x) = x^2 – a与x轴的交点。可以在x轴上先任选一点x0,则点(x0, f(x0))在f(x)上的切线,与x轴的交点为x1,它们满足切线的方程:f(x0)=(x0-x1)f’(x0),可得x1更接近最终的结果,解方程得到:x1 = (x0 + (a/x0))/2。以x1为新的x0,按照切线的方法依次迭代下去,最终求得符合精确度要求的结果...原创 2018-08-21 14:30:07 · 989 阅读 · 0 评论 -
线性表的顺序表示和基本操作的实现
#include <stdio.h> #include<process.h> #include<stdlib.h> #include<ctype.h> #include<limits.h> #include <malloc.h> using namespace std; typedef long long ll; #defi...原创 2018-10-25 14:40:57 · 202 阅读 · 0 评论 -
单向链表基本操作
# include <bits/stdc++.h> using namespace std; #include<malloc.h> typedef struct Node { int data; struct Node *pNext; }Node, *pNode; void malloc_fail(pNode p) { if (p == NULL) { p...原创 2018-10-25 16:27:24 · 144 阅读 · 0 评论 -
单链表的交集与差集
#include <stdio.h> #include <stdlib.h> typedef struct node { int data; struct node* next; }node; void push(node **head_ref, int new_data); bool isPresent(node *head, int data); node *ge...原创 2018-10-25 21:43:05 · 283 阅读 · 0 评论 -
表达式求值实现c语言
#include<bits/stdc++.h> #define STACK_INIT_SIZE 100 using namespace std; typedef struct { char date[STACK_INIT_SIZE]; int top; }OptrStack; typedef struct { double date[STACK_INIT_SI...原创 2018-10-25 21:57:57 · 1679 阅读 · 0 评论 -
链队列的基本操作
#include<bits/stdc++.h> #define STACK_INIT_SIZE 100 using namespace std; typedef struct QNode { int data; struct QNode *next; } QNode,*QueuePtr; typedef struct { QueuePtr front; ...原创 2018-10-25 22:01:48 · 123 阅读 · 0 评论 -
字符串对字符串的插入
#include<iostream> using namespace std; #define MAXLEN 255 typedef struct { char ch[MAXLEN + 1]; int length; } SString; void insert(SString&S, SString T, int pos) { SString Stem...原创 2018-10-25 22:11:12 · 354 阅读 · 0 评论 -
数据结构 哈夫曼算法的实现
#include <bits/stdc++.h> using namespace std; #define N 4//带权值的叶子节点数或者是需要编码的字符数 #define M 2*N-1//n个叶子节点构造的哈夫曼树有2n-1个结点 #define MAX 10000 typedef char TElemType; //静态三叉链表存储结构 typedef struct{ //...原创 2018-11-06 13:47:43 · 648 阅读 · 0 评论 -
二维线段树模板
最近碰到了,留个板子 void update_x(int rooty, int rootx, int L, int R, int x, int a) //tree[rooty][rootx]对应的矩阵x方向上范围是[L,R] { tree[rooty][rootx] += a; if( L == R ) return; int mid = (L + R )/2; if( x...原创 2018-12-12 20:10:05 · 232 阅读 · 0 评论 -
整除分块
对于求解以上公式时 不难发现 n/i等于k时 n往往是连续一段段的 那么就可以计算这个长度直接乘 使得复杂度由O(n)降到了O(sqrt(n)) ans=0; for(int l,r;i<=n;l=r+1) { r=n/(n/l); ans+=(r-l+1)*(n/l); } ...原创 2019-09-27 20:21:50 · 167 阅读 · 0 评论