上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 25 下一页
摘要: 【算法】简单数学 【题解】 对于A*B=C C中第i行第j列的数字由A中第i行和B中的j列的数字各自相乘后相加得到。 所以两个矩阵能相乘要求A的列数等于B的行数,复杂度为O(n3)。 #include<cstdio> #include<algorithm> #include<cstring> usi 阅读全文
posted @ 2017-06-06 21:13 ONION_CYC 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 【算法】动态规划 【题解】经典模型:最长上升子序列(n log n) #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn=50010; int a[maxn],b[max 阅读全文
posted @ 2017-06-06 20:58 ONION_CYC 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 【算法】数学 【题解】斯特林公式: #include<cstdio> #include<algorithm> #include<cmath> using namespace std; const double pi=3.1415926535898,e=2.718281828459; int main 阅读全文
posted @ 2017-06-06 20:43 ONION_CYC 阅读(460) 评论(0) 推荐(1) 编辑
摘要: 【算法】回文树 #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn=100010; struct trees{int len,fail,t[260];}t[maxn]; 阅读全文
posted @ 2017-06-05 17:31 ONION_CYC 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 【算法】DP #include<cstdio> #include<algorithm> using namespace std; const int MOD=1000000007,maxn=1010; int f[maxn][maxn]; int mods(int x) {return x>MOD? 阅读全文
posted @ 2017-06-03 14:16 ONION_CYC 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 【算法】数学 #include<cstdio> #include<cmath> bool ok(int x) { int m=(int)sqrt(x+0.5); for(int i=2;i<=m;i++) { if(x%i==0)return 0; } return 1; } int main() 阅读全文
posted @ 2017-06-02 22:01 ONION_CYC 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 【算法】背包DP 【题解】f[j]=(f[j-w[i]]+v[i]) 记得倒序(一个物品只能取一次) #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn=10010; i 阅读全文
posted @ 2017-06-01 18:38 ONION_CYC 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 【算法】树状数组(区间和) 【题解】记得开long long #include<cstdio> #include<cstring> #include<algorithm> #define lowbit(x) (x&(-x)) using namespace std; const int maxn=5 阅读全文
posted @ 2017-06-01 18:28 ONION_CYC 阅读(160) 评论(0) 推荐(0) 编辑
摘要: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn=100010; int t[maxn][2],f[maxn],s[maxn],lmax[maxn],lmin[maxn 阅读全文
posted @ 2017-05-31 21:59 ONION_CYC 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 【算法】区间DP 【题解】 参考写法:BZOJ 3971 Матрёшка 解题报告 第二个DP可以预处理mex优化到O(nM+n2),不过我懒…… 第一个DP有另一种写法:不预处理,在一个n2取出来的的区间中,枚举决策点从左到右时,保留左最小值的可保留数不严格单调递增,保留右最小值的可保留数不严格 阅读全文
posted @ 2017-05-31 20:15 ONION_CYC 阅读(398) 评论(0) 推荐(0) 编辑
摘要: 【算法】数学 【题解】n!的位数相当于ans=log10(n!)上取整,然后就可以拆出来加了。 可以用log10(i)或log(i)/log(10) 阶乘好像有个斯特林公式…… #include<cstdio> #include<cmath> using namespace std; int mai 阅读全文
posted @ 2017-05-29 22:20 ONION_CYC 阅读(271) 评论(0) 推荐(0) 编辑
摘要: 【算法】DP 【题解】开long long…… #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn=50010; int a[maxn],n; int main() { 阅读全文
posted @ 2017-05-29 22:04 ONION_CYC 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 【算法】splay 【题解】 splay维护序列,用权值(离散化)作为编号。每次找第i小的话直接找对应编号splay即可。 但是这样splay没有下传翻转标记?直接暴力找到路径然后从根到改结点pushdown。暴力出奇迹! 如果没有find就直接splay,一定记得更新设置splay为传值调用并且在 阅读全文
posted @ 2017-05-28 22:01 ONION_CYC 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 【算法】splay 【题解】对于每个结点维护其子树串的hash值,前面为高位,后面为低位。 sum[x]=sum[L]*base[s[R]+1]+A[x]*base[s[R]]+sum[R],其中sum为哈希,base为乘权,A为数值(即字符)。 #include<cstdio> #include< 阅读全文
posted @ 2017-05-28 21:54 ONION_CYC 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 【算法】splay 【题解】数据结构 感谢Occult的模板>_<:HYSBZ 1500 维修数列 #include<cstdio> #include<cctype> #include<cstring> #include<queue> #include<algorithm> using namesp 阅读全文
posted @ 2017-05-28 19:58 ONION_CYC 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 【算法】快速幂运算 【题解】快速幂的原理是把幂用二进制表示,从最低位a,次低位a2,次次低位(a2)2。 #include<cstdio> long long quick_pow(long long a,long long b,long long c) { long long ans=1; whil 阅读全文
posted @ 2017-05-28 18:37 ONION_CYC 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 【算法】离散化+树状数组(求逆序对) 【题解】经典,原理是统计在i之前插入的且值≤i的个数,然后答案就是i-getsum(i) #include<cstdio> #include<algorithm> #include<cstring> #define lowbit(x) x&(-x) using 阅读全文
posted @ 2017-05-28 18:28 ONION_CYC 阅读(316) 评论(0) 推荐(0) 编辑
摘要: 【算法】排序 #include<cstdio> #include<algorithm> using namespace std; int n,a[50010]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&a[i]); 阅读全文
posted @ 2017-05-26 19:11 ONION_CYC 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 【算法】欧几里德算法 #include<cstdio> int gcd(int a,int b) {return b==0?a:gcd(b,a%b);} int main() { int a,b; scanf("%d%d",&a,&b); printf("%lld",1ll*a*b/gcd(a,b) 阅读全文
posted @ 2017-05-26 19:05 ONION_CYC 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 【算法】欧几里德算法 #include<cstdio> int gcd(int a,int b) {return b==0?a:gcd(b,a%b);} int main() { int a,b; scanf("%d%d",&a,&b); printf("%d",gcd(a,b)); return 阅读全文
posted @ 2017-05-26 19:04 ONION_CYC 阅读(110) 评论(0) 推荐(0) 编辑
上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 25 下一页