摘要: 以32位无符号整型为例。 1: int Count(unsigned x) { 2: x = x - ((x >> 1) & 0x55555555); 3: x = (x & 0x33333333) + ((x >> 2) & 0x33333333); 4: x = (x + (x >> 4)) & 0x0F0F0F0F; 5: x = x + (x >> 8); 6: x = x + (x >> 16); 7: return x & 0x000... 阅读全文
posted @ 2011-09-05 19:40 CSDN大笨狼 阅读(247) 评论(0) 推荐(0) 编辑
摘要: 主定理(master theorem)T(n)=aT(n/b)+cna<b, T(n)=O(n);a=b, T(n)=O(nlogn);a>b, T(n)=O(nlogba)//b为底 logba 为n的次数你懂得,你不懂,我也没办法。 阅读全文
posted @ 2011-09-02 11:18 CSDN大笨狼 阅读(371) 评论(0) 推荐(0) 编辑
摘要: --create table Oders (OdersID int identity(1,1) primary key, UsersID int)--create table OderIterms( OdersID int,ProductID int)--create table Product(ProductID int identity(1,1) primary key , ProductName varchar(50) )--create table Users(UsersID int identity(1,1) primary key,gender bit,age int )--dec 阅读全文
posted @ 2011-07-22 01:14 CSDN大笨狼 阅读(407) 评论(0) 推荐(0) 编辑
摘要: O(1)的时间,根据前一组合枚举下一组合using System;namespace ConsoleApplication2{ class Program { static void Main(string[] args) { combian(5, 3); Console.Read(); } static void combian(int n, int k) { if (!(n >= k && k > 0 && n < 30)) { return; } int ik = (1 << k) - 1; while (ik != 0) { 阅读全文
posted @ 2011-07-20 08:00 CSDN大笨狼 阅读(378) 评论(0) 推荐(0) 编辑
摘要: 微软的面试题,我做过。鸽巢原理。using System;using System.Linq;using System.Collections.Generic;namespace ConsoleApplication1{ class Program { static Random Rand = new Random(); static void Main(string[] args) { int count = 10000; List<int> Input = new List<int>(); for (int i = 0; i < count; i++) { I 阅读全文
posted @ 2011-07-10 01:30 CSDN大笨狼 阅读(1020) 评论(1) 推荐(0) 编辑
摘要: 25匹赛马,5个跑道,也就是说每次有5匹马可以同时比赛。问最少比赛多少次可以知道跑得最快的5匹马? 阅读全文
posted @ 2011-07-10 01:23 CSDN大笨狼 阅读(617) 评论(3) 推荐(0) 编辑
摘要: 最近点对问题,三分治法,和求中位数思路是一样的,1,随机选一个数X,线性扫描,比X小的一堆A,比X大的一堆B,同时可以得到Min=Min(MinB-X,x-MaxA)2, 对于这两堆,分别重复1的步骤,直到结束。求中位数,需要抛弃掉一半数据,只求其中一个子集合的n/2-k大即可。《算法概论》上有证明递推式复杂度的通式。对于递推式T(n)=aT(n/b)+O(n^d)有如下结论:1,当d>log(b,a)时复杂度是O(n^d)2,当d=log(b,a)时复杂度是O(n^d*logn)3, 当d<log(b,a)时复杂度是O(n^(log(b,a))这个公式可以适用于快速排序,中位数等 阅读全文
posted @ 2011-07-06 17:03 CSDN大笨狼 阅读(1059) 评论(0) 推荐(0) 编辑
摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Numerics;using System.Globalization;using System.Diagnostics;namespace ConsoleApplication11{ class Program { static int[] HowMuch1 = new int[] { 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4, 阅读全文
posted @ 2011-07-05 01:15 CSDN大笨狼 阅读(341) 评论(1) 推荐(0) 编辑
摘要: using System;using System.Collections.Generic;using System.IO;using System.Text;namespace ConsoleApplication1{ public class Idiom { public static Dictionary<Char, List<int>> Dict = new Dictionary<char, List<int>>(); public static List<Idiom> IdiomList = new List<Idio 阅读全文
posted @ 2011-07-01 19:19 CSDN大笨狼 阅读(374) 评论(1) 推荐(0) 编辑
摘要: 再次展示算法的力量!~~三分钟的程序优化到了90毫秒,还是那句话,位运算神马的最给力了。 阅读全文
posted @ 2011-06-29 17:29 CSDN大笨狼 阅读(1144) 评论(5) 推荐(1) 编辑