2012年10月28日
摘要: Problem Description:Let X[1...n] and Y[1...n] be two arrays, each containing n numbers already in sorted order.Give an O(lgn)-time algorithm to find the median of all 2n elements in array X and Y.问题描述:X和Y是两个长度均为n的已排序数组,现要求以O(lgn)的时间复杂度找到两个数组中所有2n个数的中值。(注:这里中值被定义为:对于奇数个数,排序后中间那个,或者对于偶数个数,排序后中间两个数下标较小 阅读全文
posted @ 2012-10-28 23:18 Snser 阅读(799) 评论(0) 推荐(0) 编辑
摘要: 本文是后续文章中涉及到的基本函数源代码。001、生成随机数View Code 1 unsigned int latestRandNum = 1; 2 3 /*设置随机数种子*/ 4 void srandGLibC(unsigned int seed) 5 { 6 latestRandNum = (seed == 0 ? 1 : seed); 7 } 8 9 /*生成[0, 2147483647]之间的随机数*/10 int randGLibC(void)11 {12 int randNum = ((latestRandNum * 1103515245) + 12345) ... 阅读全文
posted @ 2012-10-28 23:15 Snser 阅读(455) 评论(0) 推荐(0) 编辑