
Algorithms
文章平均质量分 68
Southan97
本科计算机科学与技术专业,现软件工程专业在读研究生
展开
-
打印杨辉三角系数(Pascal's Triangle / 二项式展开系数)队列实现
打印杨辉三角系数(Pascal's Triangle / 二项式展开系数)队列实现原创 2017-03-11 14:25:42 · 1240 阅读 · 0 评论 -
Java 高精度开根!(BZOJ 1213)
给定m,n (1≤m≤50,0≤n≤1010000)m, n~(1 \le m \le 50, 0 \le n \le 10^{10000}) 求 n√m\sqrt[m]{n}的整数部分. 因为只要求整数部分,所以不必用 BigDecimal 类去二分,那样反而会浪费时间,最后判断边界值即可. 构造至 : lm<=n<rm, r=2ll^m <= n < r^m, ~原创 2017-07-18 11:30:02 · 1091 阅读 · 0 评论 -
Floyd Dijkstra Bellman-Ford spfa 四种最短路经典算法汇总 HDU 2544为例
求单源最短路径,本文包括了Floyd, Dijkstra, Bellman-Ford, Spfa算法。原创 2017-03-25 21:20:46 · 943 阅读 · 0 评论 -
数论基础(gcd + 拓展欧几里得)
求连个数的最大公约数gcd,拓展欧几得, 费马小定理, 取模运算性质,乘法逆元。 欧几里得定理: gcd(a, b) = gcd(b, a%b); gcd(a,b)=gcd(b,a)=gcd(-a,b)=gcd(|a|,|b|) 扩展欧几里德算法是用来在已知a, b求解一组x,y使得ax+by = Gcd(a, b) =d(解一定存在,根据数论中的相关定理)。扩展欧几里德常用在求解模线性方程及方程组中。原创 2017-03-11 21:46:40 · 613 阅读 · 1 评论 -
堆排序(heap Sort)
Algorithm steps:1. Build a max heap from the input data.2. At this point, the largest item is stored at the root of the heap. Replace it with the last item of the heap followed by reducing原创 2017-05-20 10:21:33 · 374 阅读 · 0 评论 -
ZOJ_3732 Graph Reconstruction HDU4797 Havel-Hakimi
ZOJ_3732 Graph Reconstruction HDU4797 Havel-Hakimi 无向图度序列 无向图同构 Let there be a simple graph with N vertices but we just know the degree of each vertex. Is it possible to reconstruct the graph only by these information?A simple graph is an undirected gra原创 2017-01-13 17:12:54 · 613 阅读 · 0 评论 -
HDU_1025_Constructing Roads In JGShining's Kingdom
HDU 1025 二分 Constructing Roads In JGShining's Kingdom原创 2016-07-30 23:39:57 · 630 阅读 · 0 评论 -
HDU 2389 Rain on your Parade
HDU 2389 Rain on your Parade You’re giving a party in the garden of your villa by the sea. The party is a huge success, and everyone is here. It’s a warm, sunny evening, and a soothing wind sends fresh, salty air from the sea. The evening is progressing ju原创 2017-04-03 12:19:28 · 522 阅读 · 0 评论 -
DFS&BFS小结
DFS(depth first search):深度优先搜索,即一种有一定策略的枚举 核心:递归 特点: 1. 一搜到底,不通则返 2. 平等遍历,只看方向 3. 只求可行,不求最优 4. 效率过低 DFS伪代码: depthFirstSearch(v) { Label vertex v as reached. for(原创 2016-10-23 21:18:50 · 426 阅读 · 0 评论 -
博弈
重点结论:对于一个Nim游戏的局面(a1,a2,...,an),它是P-position当且仅当a1^a2^...^an=0,其中^表示位异或(xor)运算。Nim游戏是博弈论中最经典的模型(之一?),它又有着十分简单的规则和无比优美的结论,由这个游戏开始了解博弈论恐怕是最合适不过了。Nim游戏是组合游戏(Combinatorial Games)的一种,准确来说,属于“Impa转载 2017-02-22 22:07:32 · 612 阅读 · 0 评论 -
欧拉函数
欧拉函数:对于一个正整数n,小于n且和n互质的正整数(包括1)的个数,记作φ(n) 。通式:φ(x)=x*(1-1/p1)*(1-1/p2)*(1-1/p3)*(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是不为0的整数。φ(1)=1(唯一和1互质的数就是1本身)。对于质数p,φ(p) = p - 1。注意φ(1)=1.原创 2017-03-06 21:32:14 · 541 阅读 · 0 评论 -
SPOJ SERGRID Grid BFS搜索算法
SPOJ SERGRID Grid BFS搜索算法 You are on an nxm grid where each square on the grid has a digit on it. From a given square that has digit k on it, a Move consists of jumping exactly k squares in one of the four cardinal directions. A move cannot go beyond the e原创 2017-03-08 22:56:55 · 762 阅读 · 0 评论 -
快速乘 快速幂 矩阵快速幂
求pow(a, exp)% mod 的值,快速幂其实也是利用了倍增的思想在里面,比如求2^12 = 2^6 * 2^6 = 2^3 * 2^3 * 2^3 * 2^3 = 2 * 2^2 * 2 * 2^2 * 2 * 2^2 * 2 * 2^2 = 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2;即求2^12 可以用2^6 * 2^6 再进一步用之原创 2017-01-13 23:00:02 · 545 阅读 · 0 评论 -
HDU 5306 Gorgeous Sequence
HDU 5306 Gorgeous Sequence There is a sequence a of length n. We use ai to denote the i-th element in this sequence. You should do the following three types of operations to this sequence.0 x y t: For every x≤i≤y, we use min(ai,t) to replace the original原创 2017-04-11 16:19:06 · 419 阅读 · 0 评论 -
图博弈,树上删边博弈
参考自:《组合游戏略述——浅谈SG游戏的若干拓展及变形》无向图删边游戏:树的删边游戏 规则如下:* 给出一个有N个点的树,有一个点作为树的根节点。* 游戏者轮流从树中删去边,删去一条边后,不与根节点相连的部分将被移走。* 谁无路可走谁输。定理:叶子结点的SG值为0,中间节点的SG值为它的所有子节点的SG值加一后的异或和。Fusion原创 2017-04-09 19:50:31 · 2110 阅读 · 0 评论 -
POJ 3710 Christmas Game 树上删边博弈,压缩环
POJ 3710 Christmas Game 树上删边博弈 压缩环 Fusion Principle原创 2017-04-09 22:39:01 · 930 阅读 · 1 评论 -
博弈 - SG函数和SG定理
转自:http://blog.youkuaiyun.com/luomingjun12315/article/details/45555495在介绍SG函数和SG定理之前我们先介绍介绍必胜点与必败点吧.必胜点和必败点的概念: P点:必败点,换而言之,就是谁处于此位置,则在双方操作正确的情况下必败。 N点:必胜点,处于此情况下,双方操作均正确的情况下必胜转载 2017-03-30 20:42:44 · 613 阅读 · 0 评论 -
素数筛选
素数表,素数筛选法, 给定一个数num,求1到n之内的所有素数有多少并输出,并且任意给定一个介于1到num的数快速判断其是不是素数。原创 2017-01-13 22:26:17 · 398 阅读 · 0 评论 -
农夫过河问题C++递归实现
农夫过河问题C++递归实现原创 2017-11-16 22:20:52 · 5088 阅读 · 0 评论