acm模板
snbsczw
欲说还休,欲说还休,却道天凉好个秋
展开
-
字典树-数组指针实现+数组实现
提出问题给定一个字符串集合W,然后询问该集合中是否存在字符串S。eg:W={“acd”,“bcd”,“abcd”,“abcde”,“abce”,“abbce”,“accde”,“abbcc”,“adcc”},S = “abbce”,上述问题要解决的就是W中是否存在S?解决问题从最简单的暴力出发最简单的思路自然是拿S和W中的每一个字符串比较,如果有相等的就代表W中存在S,否则不存在。这个思路的时间复杂度是多少呢?首先,遍历字符集W需要O(n),然后拿S和W中的每一个字符串比较,时间复杂度也是O(原创 2021-07-27 11:35:52 · 236 阅读 · 0 评论 -
枚举圆周上的点的坐标
#include#include#include#include#include#includeusing namespace std;#define ll long long#define inf 0x3f3f3f3fconst double pi=acos(-1.0);struct nod{ double x; double y;}cir;double原创 2018-01-29 16:42:34 · 542 阅读 · 0 评论 -
分解质因数
思想: 先打一个素数表 遍历素数表,如果发现某个素数x是n的质因子,用n除以x直到n%x!=0为止#include<cstdio>#include<cstring>#include<iostream>using namespace std;#define N 10000bool isprime[N];int pri[N];int cnt=0;void ispri()//用线原创 2018-01-19 20:49:56 · 732 阅读 · 0 评论 -
快速幂&矩阵快速幂
快速幂:举个栗子; 想求3的13次方。 把13写成二进制形式 1101 从右往左 如果第i位是1,就把它看成3的i次方 上边就可以看成是3的1次方,3的4次方,3的8次方。 把这些乘起来,正好是3的13次方。 也就是说本来循环13次,现在循环4次就行了。 然后一个问题就是每一位上的3的i次方怎么求, 这个可以在从右向左遍历的时候设一个标示值,初值设为1。每向左遍历一位,标示值乘原创 2017-09-21 16:40:28 · 216 阅读 · 0 评论 -
筛法求素数&线性筛法求素数
要理解筛法求素数首先要知道一个定理, 整数唯一分解定理:任意大于等于2的正整数都有且只有一种方式写出其质因子的乘积表达式。 A =p1p2p3p4…….pn(pi是素数且pij) eg:2=2 4=2*2 12=2*2*3 36=2*2*3*3 也就是说任意一个合数都能分成一个素数和另一个数(另一个数可以是素数也可以是合数)的乘积 eg:4=2原创 2018-01-21 11:02:22 · 264 阅读 · 0 评论 -
LightOJ - 1067 lucas定理 模板
Given n different objects, you want to take k of them. How many ways to can do it?For example, say there are 4 items; you want to take 2 of them. So, you can do it 6 ways.Take 1, 2Take 1, 3Take 1, 4Tak原创 2017-12-25 12:29:07 · 149 阅读 · 0 评论 -
HDU 1023(卡特兰数打表)
卡特兰数: h(0)=1; h(1)=1; h( n ) = ( ( 4*n-2 )/( n+1 )*h( n-1 ) );(n>=2) 其余递推式:h(n)=C(2n,n)/(n+1) (n=0,1,2,…) h(n)=c(2n,n)-c(2n,n-1)(n=0,1,2,…)前几项为:1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 587原创 2017-11-21 19:19:58 · 341 阅读 · 0 评论 -
指数型母函数模板
题面 HDU1521依旧是多项式相乘 不过在乘的过程中多了个排列的操作#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<iostream>using namespace std;#define ll long long #define Clear(a,b) memset(a,b,si原创 2017-12-09 13:08:43 · 320 阅读 · 0 评论 -
普通型母函数模板
题面是hdu1085普通型母函数说白了就是一个模拟多项式相乘的代码#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>#include<iostream>#define ll long longusing namespace std;#define _max 12345原创 2017-12-09 11:02:08 · 226 阅读 · 0 评论 -
线段树保姆级教程
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;int a[55555];int f[205555];int n;int t;void _build(int l,int r,int now){ if(l==r) { f[no原创 2017-08-23 17:48:48 · 219 阅读 · 0 评论 -
字典树
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int ch[200010][27]; //节点编号 int sz; //字典树节点个数 int val[200010]; //节点的值 void init() { sz=1; mem转载 2017-08-23 17:48:17 · 205 阅读 · 0 评论 -
POJ-2533 Longest Ordered Subsequence
A numeric sequence of ai is ordered if a1 < a2 < … < aN. Let the subsequence of the given numeric sequence ( a1, a2, …, aN) be any sequence ( ai1, ai2, …, aiK), where 1 <= i1 < i2 < … < iK <= N. For ex原创 2017-08-17 13:54:21 · 166 阅读 · 0 评论