
Algorithm
lihenair
这个作者很懒,什么都没留下…
展开
-
Bills
There are N number kinds of stamps with different worth. At this moment, you are allowed to use the same kinds of stamps several times, but the total number of uses of all stamps is restricted to less原创 2014-08-12 14:29:52 · 864 阅读 · 1 评论 -
Airfare
Mr. Lee has to travel various offices abroad to assist branches of each place. But he has a problem. The airfare would be real high as all offices he has to visit are in foreign countries. He wants to原创 2014-07-23 13:39:30 · 1186 阅读 · 0 评论 -
Business investment
An investor intends to earn maximum profits by investing money in many companies. However, the investment unit is 100 million won. The more each company return profits the more the investor earns prof原创 2014-06-24 14:18:02 · 1838 阅读 · 0 评论 -
An Irreducible Fraction
Though prime numbers used to belong to pure mathematics traditionally, they’re more related now to our real world thanks to the development of cryptology and computers in late 20th century.The pub转载 2014-06-01 16:14:54 · 1383 阅读 · 0 评论 -
What is satellite information in data structures?
转自:What is satellite information in data structures?Question转载 2014-05-07 13:34:55 · 877 阅读 · 0 评论 -
Find the median of 2 sort ed array.
Question:从两个已排序的转载 2014-05-03 20:40:38 · 800 阅读 · 0 评论 -
给定BST,使用大于等于当前节点的总和代替当前节点
转自:http://www.careercup.com/question?id=5679059790987264转载 2014-05-03 21:52:55 · 836 阅读 · 0 评论 -
算法导论第十一章----11.1.1-11.1.4
http://test.scripts.psu.edu/users/d/j/djh300/cmpsc465/notes-4985903869437/solutions-to-some-homework-exercises-as-shared-with-students/3-solutions-clrs-11.pdfExercise 11.1-1Suppose that a dynam转载 2014-02-27 18:20:07 · 4408 阅读 · 0 评论 -
Scores of marbles
There are two boxes, A and B with shelves, a and b. Following the , there are marbles with numbers written from 1 to N to every shelf of the two boxes.Box A12 1原创 2014-07-23 14:29:36 · 1074 阅读 · 0 评论 -
Boyer-Moore算法
转自:http://blog.youkuaiyun.com/appleprince88/article/details/11881323转载 2014-07-23 14:36:23 · 784 阅读 · 0 评论 -
Taekwondo
There are an individual match and group match in Taekwondo. An individual match is between two players and a group match is repetition of matches between two different individual players of each group原创 2014-08-12 14:27:45 · 1115 阅读 · 0 评论 -
Hansel and Gretel
Long time ago, there lived Hansel and Gretel. And a strange witch took Hansel to the deep forest to get rid of him. Smart Hansel abandoned scraps of bread that he’d got little by little on the way to原创 2014-07-15 11:21:41 · 2095 阅读 · 0 评论 -
Numerical Circulation
The R&D center formulated a sequence from a spectrum according to electron orbital changes. In order to create the sequence, the initial number, N & the square number, P are required. When N & P are原创 2014-07-15 11:30:41 · 893 阅读 · 0 评论 -
Returning Home
The farmer wants to return home, Farm No. 1 from Farm No. N. The farmer who is very tired is going to return home as fast as he can.In the farms he cultivates, there is the total number of T of tw原创 2014-07-15 11:24:18 · 1439 阅读 · 0 评论 -
Juice
Mr. K has made healthy juice for his colleagues. This has been made of 100% natural vitamin C especially for overcoming fatigue. With powder from various natural fruits in it, it has diverse colors, p转载 2014-06-01 15:59:12 · 1133 阅读 · 0 评论 -
B-tree, AVL tree, RB tree
参考:http://stackoverflow.com/questions/1589556/when-to-choose-rb-tree-b-tree-or-avl-tree/1589587#1589587http://stackoverflow.com/questions/647537/b-tree-faster-than-avl-or-redblack-tree/1195288#1转载 2014-07-04 13:04:01 · 1719 阅读 · 0 评论 -
算法导论第十章----10.2-1-10.2-7
10.2-1Can you implement the dynamic-set operation INSERTon a singly linked list in O(1) time? How about DELETE?使用尾指针:insert(LinkList *tail, ElemType x){ Node* p = new Node; p->value = x原创 2014-01-09 19:00:53 · 2197 阅读 · 0 评论 -
Snake Number
蛇形数类似这样的数组8 1 2 3 4 5 6 7 828 29 30 31 32 33 34 927 48 49 50 51 52 35 1026 47 60 61 62 53 36 1125 46 59 64 63 54 37 1224 45 58 57 56 55 38 1323 44 43 42 41 40 39 14原创 2013-12-22 13:16:50 · 911 阅读 · 0 评论 -
random selection
转自算法导论中文版第9.2节线性时间期望的选择算法randomized-select的期望运行时间为Θ(n)。该算饭是一个随机算法,只处理划分的一边。伪代码RANDOMIZED-SELECT(A, p, r, i)1 if p = r2 then return A[p]3 q = RANDOMIZED-PARTATION转载 2013-12-19 17:53:16 · 2417 阅读 · 0 评论 -
QuickSort
QuickSort是一种原地排序算法,不稳定。最坏情况是O(n2),平均和最好情况是O(nlogn)/* * #include * * void swp(int *a, int *b) * { * if (a != b) { * *a = *a^*b; * *b = *a^*b; * *a = *a^*b; * } *转载 2013-12-03 16:25:51 · 762 阅读 · 0 评论 -
树的性质
离散数学第7章定理2带有n个顶点的树含有n-1条边。定理3带有i个内点的正则m元树含有n=mi+1个顶点。定理4一个正则m元树若带有(i)n个顶点,则带有i=(n-1)/m个内点和l=[(m-1)n+1]/m个树叶;(ii)i个内点,则带有n=mi+1个顶点和l=(m-1)i+1个树叶;(iii)l个树叶,则带有n=(ml-1)/(m-1)个翻译 2013-12-02 22:31:04 · 1247 阅读 · 0 评论 -
Service Center
Electronics Service Center was visited by a total of N customersService Center has a total of M employees.To those employees that customers visit in order to get in line, line stands, if the servi转载 2013-12-09 14:26:56 · 1044 阅读 · 0 评论 -
Picking up Jewels
Picking up JewelsThere is a maze that has one entrance and one exit.Jewels are placed in passages of the maze.You want to pick up the jewels after getting into the maze through the entranc转载 2013-12-09 18:53:23 · 3175 阅读 · 0 评论 -
Sky Map
You are making “sky map” to represent constellation (group of starts) in the sky.In each element, 1 means star, 0 means empty.And in a constellation, each start should have at least one connect转载 2013-12-09 14:25:18 · 1492 阅读 · 0 评论 -
选择排序----select sort
选择排序是一种原地排序算法。时间复杂度为O(n2)#include void swp(int *a, int *b){ *a = *a^*b; *b = *a^*b; *a = *a^*b;}int main(void){ int i; int a[10] = { 8, 5, 2, 6, 9, 3, 1, 4, 0, 7 };原创 2013-12-02 13:25:05 · 839 阅读 · 0 评论 -
堆排序
堆排序分为最大堆和最小堆,分别是二叉树根节点和子树的根节点比节点大或小,将数组转化为完全二叉树。http://mindlee.net/2011/07/27/heap-sort-and-priority-queue/迭代部分参考wiki的修改http://zh.wikipedia.org/wiki/%E5%A0%86%E6%8E%92%E5%BA%8F#include转载 2013-11-21 09:54:11 · 912 阅读 · 0 评论 -
二分图学习笔记
偶图定义若把简单图G的顶点集分成两个不相交的非空集合V1和V2,使得图里的每一条条边都连接着V1里的一个顶点与V2里的一个顶点(因此G里没有边是连接着V1里的两个顶点或V2里的两个顶点),则G称为偶图。当次条件成立,称(V1,V2)为G的顶点集的一个二部划分。偶图也称为二部图,二分图。判断简单图是否为偶图一个简单图是偶图,当且仅当能够对图中的每一个顶点赋以两种不同的颜色,而不让原创 2013-11-26 14:42:37 · 2699 阅读 · 0 评论 -
random quicksort
快速排序的随机化版本快速排序的平均情况运行时间与最佳情况的运行时间很接近,而不是非常接近于最坏情况运行时间。快速排序的平均情况是指假定输入数据的所有排列是等可能的。可以在算法中加入随机化的成分,以便对于所有输入,它均能获得较好的平均情况性能。很多人都认为,快速排序的随机化版本是对足够大的输入的理想选择。RANDOMIZED-PARTITION(A, p, r)1转载 2013-12-11 10:53:35 · 1551 阅读 · 0 评论 -
Bus Route
Bus RouteMr. Shim received a request to improve bus routes of a complex city and he researched the bus operation policy of this city.In the city, it operates a bus for all roads from a dep转载 2013-12-11 11:18:08 · 2469 阅读 · 1 评论 -
radix-sort
基数排序(radix sort)是一种用在老师穿卡机上的算法。一张卡片有80列,每一列可以在12个位置中的任一处穿孔。排序器可以被机械的“程序化”,以便对一叠卡片中的每一列进行检查,再根据穿孔的位置将它们分别入12个盒子里。这样,操作员就可以逐个地将它们收集起来,其中第一个位置穿孔的放在最上面,第二个位置穿孔的其次,等等。对十进制数字来说,每列中只用到10个位置。一个d位数占用d个列。转载 2013-12-09 17:11:03 · 5068 阅读 · 0 评论 -
算法导论第九章9.3.7----最接近中位数的k个数
转自:mosfet.isu.edu/classes/cs385f10/resources/Introduction%20to%20Algorithms(Instructor's%20Manual).pdf(CLRS 9.3-7) Describe an O(n) algorithm that, given a set S of n distinct numbersand a posit翻译 2013-12-30 18:34:09 · 3099 阅读 · 0 评论 -
算法导论第九章9.3.6----k分位数
转自:http://dreamkorea.tistory.com/attachment/jk37.pdf9.3-6The kth quantiles of an n-element set are the k-1 order statistics that divide thesorted set into k equal-sized sets (to within1). Give翻译 2013-12-31 09:53:19 · 5184 阅读 · 1 评论 -
Partial Sequence of the Longest Increase
Partial Sequence of the Longest IncreaseA problem to find a partial sequence of the longest increase is well-known in the algorism field.This sequence is defined as the longest sequence among转载 2013-12-06 08:15:04 · 1600 阅读 · 0 评论 -
A Gentle Introduction to Algorithm Complexity Analysis
转自http://discrete.gr/complexity/IntroductionA lot of programmers that make some of the coolest and most useful software today, such as many of the stuff we see on the Internet or use daily转载 2013-12-13 09:10:08 · 1980 阅读 · 0 评论 -
counting sort
转自算法导论第二版8.2节计数排序不是比较排序。计数排序是用了输入元素的实际值来确定它们在数组中的位置。计数排序假设n个输入数据中的每一个都是介于0到k之间的整数,此外k为某个整数。当k=O(n)时,计数排序的运算时间为Θ(n)。注意这个算法的前提是每个数据都是0计数排序的基本思想就是对每个输入元素x,确定出小于x的元素个数。有了这个信息,就可以把x直接放到他在最终输出数组转载 2013-12-05 11:25:39 · 1793 阅读 · 0 评论 -
insert sort
插入排序时一种原地排序算法,稳定的伪代码INSERT-SORT(A)1 for i 2 do key 3 j 4 while j > 0 and A[j] > key5 do A[j+1] 6 j 7 A[j+1] = key#inclu原创 2013-12-04 17:04:11 · 889 阅读 · 0 评论 -
sort
冒泡排序void bubble(int a[], int size){ int i, j, tmp; for (i = 0; i < size; i++) { for (j = size; j >= i; j--) { if (a[j] < a[i]) { tmp = a[i]; a[i] = a[j]; a[j] = tmp;原创 2012-07-28 22:11:29 · 548 阅读 · 0 评论