- 博客(26)
- 收藏
- 关注
原创 扩展中国剩余定理
扩展中国剩余定理x = a[1] (b[1])x = a2x = a[1] + k1[b1];x = a[2] + k2[b2]k1[b1] + (-k2[b2]) = a[2] - a[1] ;c = a[2] - a[1]c = a[2] - x ;lt excrt(){ lt x,y,k; lt M=bi[1],ans=ai[1];//第一个方程的解特判 ...
2019-08-19 10:54:52
120
原创 快速乘
快速乘模板二进制ll ksc(ll x ,ll y ,ll mod){ ll res = 0; while(y) { if(y&1) res += (res + x)%mod; x = (x<<1)%mod; y >>=1; }}奇怪的(o)1公式l...
2019-08-19 08:22:36
112
原创 高斯消元
高斯消元模板#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>using namespace std;double map[120][120] ,ans[120];//double eps=1e-7;double eps=1e-7;int mai...
2019-08-17 20:59:39
101
原创 P2742 【模板】二维凸包 / [USACO5.1]圈奶牛Fencing the Cows
凸包模板#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cstring>#include <queue>#include <cmath>using namespace std;c...
2019-08-12 19:51:20
105
原创 D - Josephina and RPG(概率DP)
概率dpdp[i][j] i 存的是进行了几轮比赛j 存的是剩下的比赛用什么去打从后面往前面进行,先算出来最后一轮各个点对最后一队获胜的概率,呢么倒数第二组的概率就是任意一个点和倒数第二个点的概率加上 max(倒数第一个的概率和刚才的呢个点或者是倒一点和道二)也就是换没换点,然后合并最后两个点,在此假设只有两个点,以此循环。#include <bits/stdc++.h...
2019-08-09 19:53:10
93
原创 贪心加二分
贪心加二分题目K - Video Reviews Gym - 101755K最少需要m个,二分可以加快速度,假设可以说服m/2个人就可以,如果不行,说明要说服的人在m/2-m之间,如果可以吧m/2当做m在进行操作#include <iostream>#include <algorithm>#include <cstdio>#include <...
2019-08-07 08:30:59
187
原创 树形DP
树形DP例题A - Anniversary party(树形DP)题意有n个人要开一个PARTY,编号1到n,每个人都有一个欢乐值,并且每个人都有一个直接上司,为了让气氛更好,要求在这n个人中选一些人去参加PARTY,并且选出的这些人中任意两个人之间都没有直接上司或直接下属关系,求选出人的最大欢乐值。思路:一个模板树形dp。dp[i][1] 选i这个人dp[i][0]不选这个人。和普通d...
2019-08-06 14:43:25
473
原创 三角形面积的叉积公式
叉积公式a(x1,y1),b(x2,y2),c(x3,y3);S=0.5abs((x2-x1)(y3-y1)-(y2-y1)*(x3-x1));例题B - Minimal Area Gym - 101755B#include <iostream>#include<cstdio>#include<algorithm>#include<cstd...
2019-08-06 13:36:40
4939
原创 AC自动机
标题#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<queue>#include<algorithm>using namespace std;struct Tre...
2019-08-03 16:02:11
75
原创 Manacher
Manacher#include <iostream>#include <cstring>#include <algorithm>#include<cstdio>using namespace std;char s[100];char s_new[100];int p[100];int Init(){ int len ...
2019-08-03 09:54:58
71
转载 前缀和加二分
B - Glider Gym - 101911B#include<iostream>#include<cstdio>#include<map>#include<set>using namespace std;struct node{ int l, r ;} x[200005];int a[200005], b[200005]...
2019-08-01 16:14:17
262
原创 扩展KMP
扩展KMP注意p0存的是当前遍历s最远的点的起始点例如 s aaaaabaa t aaaabextend[0] = 4 ;extend[1] = 5;此时p0 = 1 ;因为 s遍历到了 b,是从第二个a开始遍历的s p0 对应t 的 1#include <bits/stdc++.h>using namespace std;const in...
2019-07-31 21:23:58
71
原创 分块
分块block 每一块的大小num 分成num块belong[ ] 第几个数属于哪一块l[ ] 每一块的最左边r[ ] 每一块的最右边#include <iostream>#include <stdio.h>#include<string.h>#include<stdlib.h>#include <algor...
2019-07-29 20:59:27
86
原创 离散化
离散化处理操作简单介绍:a ,b为左右边界,把n条变的左右边界存好,然后排序。列如 原来的变为 1 -100 4- 58 5- 79排序之后变为 1 4 5 58 79 100然后 1 为左边界 设为第一条边的左边界,1映射为14 为左边界 设为第2条边的左边界,4映射为25 为左边界 设为第3条边的左边界,5映射为358 ...
2019-07-29 09:42:54
79
原创 树状数组
树状数组#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>using namespace std;int n,m,tree[2000010];int lowbit(int n){ re...
2019-07-28 20:02:32
69
原创 矩阵快速幂
矩阵快速幂矩阵快速幂和整数快速幂没有什么差别,唯一的差别在于,先写一个矩阵相乘的函数,比如a为一个矩阵,求a^10。先定义一个函数求两个矩阵相乘#include<bits/stdc++.h>#define mod 10000#define N 2struct node{ int m[N+1][N+1]; node() { m[1][...
2019-07-27 14:08:34
80
原创 归并排序
``归并排序#include<bits/stdc++.h>using namespace std;int a[100] ,temp[100] ;void meme(int s,int e,int s1,int e1)//把两端合成一段 而且两端都已经是排好序的所以复杂度低{ int k = s ,s3 = s,s4 = s1 ; while(s3<=e...
2019-07-26 21:40:41
218
原创 线性筛模板
#include<bits/stdc++.h>using namespace std;const int maxn = 100 ;int prime[maxn*2];int vis[maxn*2];int main(){ int k = 0; for(int i = 2; i<=maxn;i++) { if(vis[i]==0)...
2019-07-24 10:11:45
80
转载 次小生成树
F - The Unique MST `#include <vector>#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define INF 0x3f3f3f3fusing namespace std;int n,m;...
2019-07-23 19:44:50
72
转载 最小生成树是否唯一
判断最小生成树是否唯一的Kruskal算法#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N=11000;const int M=15005;int n,m,cnt;int pare...
2019-07-22 20:24:39
722
1
原创 快速幂
#include <bits/stdc++.h>using namespace std;long long qsm(long long a, long long b){ int ans = 1,base = a; while(b != 0) { if(b & 1)//如果最后一位是1 ans *= base...
2019-06-28 21:25:41
60
原创 dijkstra优先队列优化
标题B - Bumped! Kattis - bumped 在这里插入代码片#include <bits/stdc++.h>typedef long long ll ;const ll maxn = 150010 ;const ll inf = 1e10 ;using namespace std;struct node{int v ;ll cost ;node(in...
2019-06-21 20:23:25
323
原创 单调队列
@[TOC](这最大## 标题里写自定义目录标题)最大子序和在这里插入代码片在这里插入代码片#include<cstdio>#include<algorithm>///单调队列,#include<cstring>#include<list>#include<deque>using namespace std;typedef ...
2019-06-19 20:27:57
71
原创 最小费用最大流
最小费最大流#include<bits/stdc++.h>#define Ll long longusing namespace std;const int N=5e3+5;queue<int>Q;//v是流量,c是花费struct cs{ int to,nxt,v,c;} a[N*20];int head[N],ll=1;int dist[N]...
2019-06-13 23:28:17
79
转载 KM算法
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int MAXN = 305;const int INF = 0x3f3f3f3f;int love[MAXN][MAXN]; // 记录每个妹子和每个男生的好感度int ex_gi...
2019-06-08 17:20:29
100
原创 网络最大流
在这里插入代码片输入4 5 4 34 2 304 3 202 3 202 1 301 3 40输出50`网络最大流##@TOC网络最大流#include #include #include #include #include using namespace std;#define inf 0x7fffffffstruct Edge{int v,w,nxt;...
2019-06-08 17:18:26
125
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人