算法
文章平均质量分 69
白白不狼
我是菜b
展开
-
快速幂取余
这个快速幂排序原理是基于秦九昭算法然后这里需要知道一个公式 a^b%c=(a%c)^b%c,这个离散和数论里应该都讲的有 具体证明可以百度 不多说废话直接贴模版int PowerMod(int a,int b,int c){ int ans=1; a=a%c; while(b>0) { if(b%2==1)原创 2017-07-26 16:57:49 · 188 阅读 · 0 评论 -
分治法求最近点对
一维最近点对(数轴上)模版:#includeusing namespace std;const int inf=0x3f3f3f3f;//赋大值double s[100];double mn;double closest(int low,int high){ if(low+1==high) return s[high]-s[low];原创 2018-01-27 20:09:53 · 916 阅读 · 0 评论 -
数状数组
数状数组求解:下图是数状数组C和原数组a数状形数组的规律:•C1=a1•C2=a1+a2•C3=a3•C4=a1+a2+a3+a4•C5=a5•……•C8=a1+a2+a3+a4+a5+a6+a7+a8•……•C2n=a1+a2+….+a2^n本质:对于序列a,数组C中的第x个元素为 C[x] = a[转载 2017-12-14 17:02:33 · 436 阅读 · 0 评论 -
hdu 5510 KMP+暴力
BazingaTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 6175 Accepted Submission(s): 1905Problem DescriptionLadies and gentlemen, please sit u...原创 2017-12-11 20:45:06 · 204 阅读 · 0 评论 -
poj 2965 dfs+枚举
题目 The Pilots Brothers' refrigeratorTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 27490 Accepted: 10611 Special JudgeDescriptionThe gam原创 2017-11-06 13:18:25 · 213 阅读 · 0 评论 -
#448 div.2 B.XK Segments
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and原创 2017-11-29 22:28:54 · 347 阅读 · 0 评论 -
GCD LCM
GCD欧几里德算法 又称辗转相除法 用来求最大公约数LCM 求最小公倍数这里需要知道一个结论 两个数的最小公倍数等于这两数的乘积除以它们的最大公约数int gcd(int a,int b){return b==0?a:gcd(b,a%b);}int lcm(int a,int b){ return a/gcd(a,b)*b;}这里先进行除法的目的是 a*b可能会溢出...原创 2017-07-28 12:52:46 · 521 阅读 · 0 评论 -
HDU 1061 Rightmost Digit
Problem DescriptionGiven a positive integer N, you should output the most right digit of N^N. InputThe input contains several test cases. The first line of the input is a single integer T原创 2017-07-26 17:13:12 · 156 阅读 · 0 评论 -
人见人爱A^B
Problem Description求A^B的最后三位数表示的整数。说明:A^B的含义是“A的B次方” Input输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1 Output对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。 Sample Input2 312 66789 10000原创 2017-07-26 17:10:25 · 161 阅读 · 0 评论 -
LIS 最长上升(下降)子序列(模版)
转载请注明出处:http://blog.csdn.net/u012860063最长递增子序列(Longest Increasing Subsequence)下面我们简记为:LIS。假设存在一个序列d[1..9] = 2 1 5 3 6 4 8 9 7,我们可以很轻松的看出来它的LIS长度为5。但是如果一个序列太长后,就不能直接看出来了!下面我们试着逐步找出答案。我们定义一个序列B,然后令 i = ...转载 2018-01-28 20:35:05 · 199 阅读 · 0 评论