算法模板
模板
Spikeeee-
消磨到死的那些希望的亡灵:苍白、凄惨、哭的哀伤。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
排序算法总结篇 - (堆排序, 快速排序(链表, 数组),直接插入排序,选择排序,冒泡排序, 归并排序)
1.冒泡排序(Bubble Sort):#include <stdio.h>void Pri(int a[],int s) { for(int i = 0; i < s; ++i) { printf("%d ", a[i]); } printf("\n"); return;}void Swap(int *a,int *b) { int t = *a; *a = *b; *b = t; return;}void Bubble_Sort(int a[],i原创 2021-04-20 15:01:28 · 225 阅读 · 0 评论 -
算法 - 输出保留n位有效数字
计算方法课奇奇怪怪的要求void _pri(double x, long long n, bool f) { //预处理数字,保留位数,是否需要四舍五入 double _ma = 1.0, _mi = 1.0, _t = 10.0; long long _n = n, i = 0, cnt = 0; while(_n) { if(_n % 2 == 1) _ma *= _t, _mi /= _t; _n >>= 1, _t *= _t;原创 2021-03-27 20:37:19 · 278 阅读 · 0 评论 -
边权最短路径-Floyd算法 (ACM学习笔记)
有向图,不可解决边权为负的问题#include<cstdio>#include<iostream>#include<algorithm>using namespace std;const int maxn = 1e2 + 5;const int INF = 0x3f3f3f3f;int main() { int map[maxn][maxn...原创 2020-04-28 17:31:18 · 291 阅读 · 0 评论 -
快速幂
x^ndouble QuickPow(double x, int n) { double res = 1, p = x; while (n > 0) { if (n & 1) res *= p; p = p * p; n >>= 1; } return res;}原创 2020-08-11 20:16:37 · 142 阅读 · 0 评论 -
字符串匹配算法 —— BM,KMP
Boyer-MooreKMP#include<iostream>#include<algorithm>#include<string.h>#include<string>#include<stdio.h>#include<stdlib.h>#include<math.h>#include<vector>#include <time.h>#include<windows.h&原创 2020-07-20 23:47:00 · 318 阅读 · 0 评论 -
LCT(link cut tree) -模板
//LCT Link Cut Tree(动态树) 模板//洛谷 P3690 【模板】Link Cut Tree (动态树)//2020.11.10 创建//2020.11.16 结束//0 x y: 代表询问从 x 到 y 的路径上的点的权值的 xor 和。保证 x 到 y 是联通的。//1 x y: 代表连接 x 到 y,若 x 到 y 已经联通则无需连接。//2 x y: 代表删除边(x,y),不保证边(x,y) 存在。//3 x y: 代表将点 x 上的权值变成 y。#include原创 2020-11-17 20:42:40 · 179 阅读 · 0 评论 -
Splay树-模板
tarjan杀我//对于查找频率较高的节点,使其处于离根节点相对较近的节点//我们定义一个结点与他父亲的关系是x,//那么在旋转时,他的父亲成为了他的!x儿子,//并且那个上文中所说的“多余结点”,//同时也是当前节点的!x儿子,//但在旋转之后需要成为当前节点的“前”父节点的x儿子// 1.插入 x 数// 2.删除 x 数(若有多个相同的数,则只删除一个)// 3.查询 x 数的排名(排名定义为比当前数小的数的个数 +1 )// 4.查询排名为 x 的数// 5.求 x 的前驱原创 2020-11-12 21:35:04 · 204 阅读 · 0 评论 -
LCA-模板
//Lowest Common Ancestor//2020.11.9#include <bits/stdc++.h>#define ll long long#define _for(i,a,b) for(ll i = (a);i < (b); ++i)#define sc scanf#define pr printf#define TLE ios::sync_with_stdio(false); cin.tie(0);const int maxn = 2005;con原创 2020-11-10 21:46:33 · 148 阅读 · 0 评论 -
树链剖分-模板
//P3384 【模板】轻重链剖分//2020.11.10//将树从x到y结点最短路径上所有节点的值都加上z//求树从x到y结点最短路径上所有节点的值之和//将以x为根节点的子树内所有节点值都加上z//求以x为根节点的子树内所有节点值之和#include <bits/stdc++.h>#define ll long long#define _for(i,a,b) for(ll i = (a);i < (b); ++i)#define sc scanf#define原创 2020-11-10 21:45:00 · 147 阅读 · 0 评论 -
Tarjan算法模板 - 求有向图中的强连通分量
#include <iostream>#include <cstdio>#include <cstring>#include <stack>#include <vector>#include <cmath>#include <algorithm>#define maxn 100010#define sc scanf#define pr printf using namespace std;int u,原创 2020-10-23 18:46:40 · 115 阅读 · 0 评论 -
线段树 - 模板
线段树板子0:#include<cstdio>#include<iostream>#define ll long long #define _for(i,a,b) for(ll i = (a);i < (b); ++i)using namespace std;const ll maxn = 1e5+5;void build_tree(ll arr[],ll tree[],ll node,ll start,ll end){ //printf("Start : %原创 2020-10-15 20:28:11 · 174 阅读 · 0 评论 -
Dijkstra - (ACM学习笔记)
#include<iostream>#include <algorithm>using namespace std;const int INF = 0x3f3f3f3f;const int maxn = 1e5 + 5;int dis[maxn],map[100][100],book[maxn];int m, n;void Dijkstra(int s) { for (int i = 0; i <= n; i++) dis[i] = (i == s ? 0 :原创 2020-07-08 23:11:38 · 173 阅读 · 0 评论 -
KMP模板
#include <iostream>#include <cstdio>#include <cstring>#define maxn 1000010 using namespace std;int kmp[maxn], la, lb, j;char a[maxn], b[maxn];int main() { cin >> a + 1; cin >> b + 1; la = strlen(a + 1);原创 2020-10-23 16:14:28 · 111 阅读 · 0 评论
分享