- 博客(9)
- 收藏
- 关注
原创 扩展欧几里德算法
原理 : 定义 ax+by=gcd(a,b)*k 一定会有解 所以公式变形为 ax+by=d gcd(a,b)|d d能整除gcd(a,b)ll ex_gcd(ll a,ll b,ll x,ll y){ if(!b) { x=1; y=0; return a; } ll g=ex_gcd(b,a%b,x,y),
2017-07-31 23:52:53 238
原创 素数 快速幂 gcd.lcm
一 素数1.判断一个数是不是素数 如果x<=1 则不是素数 是素数返回true 不是则返回falsebool is_pri(ll x) //时间复杂度O(√n){ ll s=sqrt(x+0.5); //加0.5是为了防止精度误差 for(ll i=2;i<=s;i++) if(!(x%i)) return false; return
2017-07-31 17:18:24 325
原创 矩阵快速幂模版
const ll mod=1000;const int N=4;struct node{ ll a[N][N]; void init() { for(int i=0;i<N;i++) for(int j=0;j<N;j++) a[i][j]=0; for(int i=0...
2017-07-24 18:27:20 183
原创 链式前向星
#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <iostream>#include <map>#include <queue>#include <cmath>#include <vector>using namespace std;typedef long long
2017-07-22 18:42:10 268
原创 RMQ 求区间最值
pku 3264#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <iostream>#include <map>#include <queue>#include <cmath>#include <vector>using namespace std;typedef
2017-07-20 12:10:26 279
原创 HDU 1466 计算直线的交点数
平面上有n条直线,且无三线共点,问这些直线能有多少种不同交点数。 比如,如果n=2,则可能的交点数量为0(平行)或者1(不平行)。 Input 输入数据包含多个测试实例,每个测试实例占一行,每行包含一个正整数n(n<=20),n表示直线的数量. Output 每个测试实例对应一行输出,从小到大列出所有相交方案,其中每个数为可能的交点数,每行的整数之间用一个空格隔开。 Sample Inp
2017-07-20 10:24:03 207
原创 SHU A序列 (最大上升子序列)
A序列描述 如果一个序列有奇数个正整数组成,不妨令此序列为a1,a2,a3,…,a2∗k+1(0<=k),并且a1,a2…ak+1是一个严格递增的序列,ak+1,ak+2,…,a2∗k+1,是一个严格递减的序列,则称此序列是A序列。比如1 2 5 4 3就是一个A序列。现在Jazz有一个长度为n的数组,他希望让你求出这个数组所有满足A序列定义的子序列里面最大的那个长度。(子序列可以不连续)比如1
2017-07-10 20:13:26 441
原创 HDU 2369 尺取法
Bruce Force’s keyboard is broken, only a few keys are still working. Bruce has figured out he can still type texts by switching the keyboard layout whenever he needs to type a letter which is currently
2017-07-08 21:50:27 221
原创 HDU 1028 (母函数或者dp)
“The second problem is, given an positive integer N, we define an equation like this: N=a[1]+a[2]+a[3]+…+a[m]; a[i]>0,1<=m<=N; My question is how many different equations you can find for a give
2017-07-02 11:19:36 406
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人