模板
YancyKahn
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【Golang基础】Go实现牛顿迭代用于计算平方根
Go实现牛顿迭代用于计算平方根牛顿迭代计算平方根的数学原理这里不做解释,给出迭代公式:要计算 x^2 = a 得到x的值。可以用以下公式进行迭代计算:下面为Go语言实现版本,作为Golang学习练习。package mainimport ( "fmt" "math")func Sqrt(x float64) float64 { lim := 1e-8 #迭代精度 count := 100 #最大迭代次数 now_index := 0 z_old := x #初始化 z_原创 2020-10-07 15:12:07 · 777 阅读 · 0 评论 -
进制转化模板
进制转化是基础中的基础, 以下是任意进制转化模板, 依照计算机的加减法是在10进制的运算表下实现的, 靠十进制实现转化.//任意进制转化十进制返回十进制数int toDec(const char *p, int frombase){ int ans = 0; while(*p) { ans *= frombase; if(isdigi...原创 2017-11-20 12:16:44 · 500 阅读 · 0 评论 -
离散化模板
数据离散化的目的是因为数据的范围过大, 把其一一映射在较小的范围,成为数据离散化.#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int MAXN = 1000;int array[MAXN]; //目标数组int list[MAXN]; //离散化数组void原创 2017-12-02 18:13:32 · 394 阅读 · 0 评论 -
欧几里得(gcd) + 拓展欧几里得(ext_gxd)
1. 欧几里得算法//求最大公约数和最小公倍数int gcb(int a, int b){ return b == 0 ? a : gcb(a, a%b);}2.拓展欧几里得求解线性方程组 ax + by + c = 0void gcd(int a, int b, int &x, int &y, int &d){ if(!b){ d = a; x原创 2017-10-21 15:02:34 · 604 阅读 · 0 评论 -
输入输出加速
//这个函数是一个“是否兼容stdio”的开关,C++为了兼容C,保证程序在使用了std::printf和std::cout的时候不发生混乱,将输出流绑到了一起。 ios::sync_with_stdio(false); //在默认的情况下cin绑定的是cout,每次执行 << 操作符的时候都要调用flush,这样会增加IO负担。可以通过tie(0)(0表示NULL)来解除cin与c原创 2018-02-12 01:05:11 · 601 阅读 · 0 评论 -
KMP模板
void getNext(string pattern, int len){ int k = -1; next[0] = -1; for(int i = 1; i < len; ++i) { while(k > -1 && pattern[k + 1] != pattern[i]) k = next[k]; if(pattern[k +原创 2018-02-12 01:06:08 · 478 阅读 · 0 评论 -
算法竞赛常用数据常量
1. 一百以内的所有素数:const int prime[26] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101};2. 数学常量: const int PI = 3.1415927; const int E = 2.71828; const i...原创 2017-11-20 12:10:33 · 492 阅读 · 0 评论 -
康托展开
康托展开原创 2018-02-27 22:16:20 · 302 阅读 · 0 评论 -
ISAP模板
网络流问题 ISAP邻接表形式const int MAXN = 100010; //点数的最大值const int MAXM = 400010; //边数的最大值const int INF = 0x3f3f3f3f;struct Edge { int to, next, cap, flow;} edge[MAXM]; //注意是MAXMint tol;int head[MAXN...转载 2018-05-17 11:42:49 · 415 阅读 · 0 评论 -
快速幂与矩阵快速幂
快速模幂typedef long long LL;const LL MOD = 100000007;LL qpow(LL x, LL n){ LL result = 1; while(n) { if(n & 1) result = result*x%MOD; n >>= 1; x ...原创 2018-07-15 18:33:41 · 300 阅读 · 0 评论 -
新博客
欢迎访问我的新博客 博客主页: https://yancykahn.github.io/ 以后会两个同时更新原创 2018-08-26 11:39:22 · 281 阅读 · 0 评论 -
Vim配置
.vimrc"set numberset nu"set tab width 4set tabstop=4set expandtabset shiftwidth=4set smarttab"c indnetset cindent"smart indentset smartindent"auto indentset autoindent"rulerset ...原创 2018-08-19 14:07:46 · 284 阅读 · 0 评论 -
Dance Links X模板(转自 Kuangbin)
【Dance Links X】Dance Links X 舞蹈链算法, 原理为一个双端十字链表的数据结构, 主要用于处理精确覆盖问题(解决n皇后问题, 数独问题)。下面的代码为 【ZOJ-3209 Treasure Map】的题解, 此题要求的是整个面积的覆盖, 把每个格子当成一个列, 然后用模板跑一次就行。#include &lt;bits/stdc++.h&gt;using name...转载 2018-09-27 21:32:40 · 519 阅读 · 0 评论 -
经典排序算法Python实现
经典排序算法python实现目录直接插入排序二分插入排序希尔排序冒泡排序快速排序简单选择排序堆排序归并排序基数排序1. 插入排序直接插入排序#!/usr/bin/env python# -*- coding:UTF-8 -*-# AUTHOR: YancyKahn# FILE: D:\Work\408_863\DataStruct\Sorting\Ins...原创 2019-10-06 20:24:42 · 515 阅读 · 0 评论 -
BigInteger模板(c++实现)
实现加法(+)和乘法(*)操作#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct BigInteger{ const static int MOD = 10000; const static int DLEN = 4; i原创 2017-11-16 19:16:02 · 1813 阅读 · 0 评论 -
最长上升子序列(LIS)和最长下降子序列(LDS)
LIS和LDS模板:const int MAXN = 100005;int a[MAXN], dp[MAXN];//最长上升子序列int LIS(int n){ int res = 0; for(int i = 0; i < n; ++i) { dp[i] = 1; for(int j = 0; j < i; ++j)原创 2017-11-29 15:07:22 · 3028 阅读 · 0 评论 -
Kruskal算法实现最小生成树
Kruskal算法 用并查集实现 注意: 1. 将图存储在邻接表中 2. 定义cmp函数实现按照图中的边权排序 3. 并查集的路径压缩使得时间复杂度降低#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;int n, m;cons原创 2017-10-21 21:30:57 · 427 阅读 · 0 评论 -
并查集(不带权 + 带权)
1. 不带权重并查集三个操作: 初始化, 查找, 合并.#include <iostream>#include <cstdio>#include <cmath>using namespace std;const int MAX_SIZE=1002;int Set_father[MAX_SIZE];int Set_Count[MAX_SIZE];void Initialization()原创 2017-10-21 14:54:26 · 403 阅读 · 0 评论 -
spfa算法
带负环的图求最小路径带负环 return FALSE, 不带负环 return TRUE; #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #defind ms(s, t) memeset(s, t, size原创 2017-10-21 18:06:46 · 321 阅读 · 0 评论 -
Floyd算法
Floyd 求两点之间的最短路径 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; //floyd algorithm const int maxn = 10000; const int INF原创 2017-10-21 17:17:46 · 344 阅读 · 0 评论 -
线段树模板(区间和+区间最大值 + LAZY标记)
线段树模板1. 区间和模板#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define maxn 50005using namespace std;//线段树模板struct node{ int l, r; int sum; //根据情况sum的类型改为ll 或者 ull原创 2017-10-16 14:27:32 · 945 阅读 · 0 评论 -
Dijkstra算法
Dijkstra 用来求无负边权的最短路径问题#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>using namespace std;//dijkstra algorithmconst int maxn = 100000;原创 2017-10-21 16:30:04 · 353 阅读 · 0 评论 -
拓扑排序(字典序)
字典序拓扑排序 1.用优先队列维护 2.从后往前排序, 每次判断节点的出度, 出度 == 0 , 进入优先队列. 3.用vector数组做邻接表表示整个图#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <queue>using namespace s原创 2017-11-03 15:36:45 · 3025 阅读 · 0 评论 -
Prim算法实现最小生成树
Prim算法: 从一个节点出发, 每次找到连接的边, 找到最小权重的边, 将边连接的节点加入集合, 找出集合中所有点连接的边, 在寻找最小边, 知道所有点都被找到. 将图存储在邻接矩阵中.#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;c原创 2017-10-21 22:48:23 · 802 阅读 · 0 评论 -
stringstream类型转换
c++标准库中的 < sstream >提供了类型转化的功能.<sstream>中定义了三个类: 1. istringstream 流输入 2. ostringstream 流输出 3. stringstream 流输入输出在类型转换时使用<ss原创 2017-11-18 14:20:32 · 1064 阅读 · 1 评论 -
扩展KMP(模式串与文本串的最长公共前缀)
const int maxn=100010; //字符串长度最大值 int next[maxn],ex[maxn]; //ex数组即为extend数组 //预处理计算next数组 void GETNEXT(char *str) { int i=0,j,po,len=strlen(str); next[0]=len;//初始化next[0] wh转载 2017-11-13 19:52:55 · 615 阅读 · 0 评论 -
Manacher(处理最长回文的类似问题)
1. 将字符串中的数变为奇数2. p[i]表示最长回文长度左右扩张的长度#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 110005;char target[maxn];char target01[maxn<<1]原创 2017-11-09 20:38:42 · 341 阅读 · 0 评论 -
KMP算法模板(字符串匹配问题)
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1000005;const int maxm = 10005;struct K_M_P{ int target[maxn]; int pattern[ma原创 2017-11-01 15:50:04 · 372 阅读 · 0 评论 -
HUD2222(ac自动机)
标准ac自动机模板题题目链接:https://vjudge.net/problem/HDU-2222#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std;//ac_automaton algorithmconst int原创 2017-11-14 18:12:52 · 465 阅读 · 0 评论 -
AC自动机模板(多模式匹配)
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std;//ac_automaton algorithmconst int MAXNODE = 1000005;const int SIGMA_SIZE = 26;//构造t原创 2017-11-14 17:36:00 · 446 阅读 · 0 评论 -
树状数组模板
一维树状数组快速求区间和, 功能和线段树相似, 查询和更新的时间复杂度都为o(log(n)).#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 1000002;ll sum[maxn原创 2017-10-21 14:42:01 · 313 阅读 · 0 评论
分享