随笔分类 -  算法/数据结构

扑克存储
摘要:_uint8 g_card[MAX_CARD+1] = { 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, //方片 3-20x31, 0x41, 0x51, 0x61, 0x71, 0x8... 阅读全文

posted @ 2015-03-18 17:22 kangbry

电梯算法
摘要:#include #define N 6int nPerson[6] = {1,2,3,4,5,6};void min_floor(int& floor, int& min){ for (int i = 0; i j ? i - j : j - i); } if ... 阅读全文

posted @ 2015-03-11 22:49 kangbry

八皇后算法
摘要:#include using namespace std; #define MAX 8int queen[MAX]={0};int sum = 0;void show(){ printf("("); for(int i =0;i<MAX;i++) { printf(" %d",queen[i... 阅读全文

posted @ 2014-11-15 00:40 kangbry

哈弗曼编码
摘要:#include "stdafx.h"#include #include #include using namespace std;#define N 5#define M 2*N-1#define MAXINT 100struct Node{ int weight; int parent; in... 阅读全文

posted @ 2014-11-13 13:26 kangbry

桶排序
摘要:桶排序 (Bucket sort)工作的原理是将阵列分到有限数量的桶子里。每个桶子再个别排序(有可能再使用别的排序算法或是以递回方式继续使用桶排序进行排序)。#includestruct barrel { int node[10]; int count; };void bucket_sort(in... 阅读全文

posted @ 2014-11-11 20:44 kangbry

海量数据重复最多
摘要:1.数据取模分批存放2.记录数字--次数映射3.找出每批中次数最多的4.每批次数最多的数再排序 阅读全文

posted @ 2014-11-11 20:16 kangbry

寻找中位数
摘要:1.数据分批加入内存2.数据按大小分多个区间,记录每个区间多少人3.推算中位数在那个区间4.对区间内数进行快排 阅读全文

posted @ 2014-11-11 20:15 kangbry

候选人算法
摘要:现在有一个整数数组,已知一个数出现的次数超过了一半,请用O(n)的复杂度的算法找出这个数#include int main(int argc, char **argv){ int i, candidate, vote; int a[10]={1,2,3,1,2,1,1,6,1,1}; candid... 阅读全文

posted @ 2014-11-11 19:43 kangbry

8亿个整数存储
摘要:用int型存储占2^32* 4 / 1000 /1000/ = 4096 * 4 M用位数组存储占 4096 * 4M /32 = 512M#include #include #include using namespace std;const unsigned int n = (-1 + 1024... 阅读全文

posted @ 2014-11-11 16:57 kangbry

tire树
摘要:#pragma once #include using namespace std;#define MAX_CHAR 26struct node { bool isWord; node* next[MAX_CHAR]; node() { isWord = false; for(int i = 0... 阅读全文

posted @ 2014-11-11 15:07 kangbry

100亿个数取前1w名
摘要:#include #include #include #include #include #include static unsigned int BUF_PAGES; /* 缓冲区有多少个page */static unsigned int PAGE_SIZE; ... 阅读全文

posted @ 2014-11-11 13:30 kangbry

排名算法
摘要:#include#includeusing namespace std;struct BinaryTree{ int count;// 该节点的孩子总数 int from_score; int to_score; BinaryTree* left; BinaryTree* right; Binary... 阅读全文

posted @ 2014-11-09 23:58 kangbry

kmp算法
摘要:kmp算法//计算偏移值void get_next(const char pat[], int next[]) { memset(next,0,sizeof(next)); int i=-1,j=0;next[0]=-1; while(j < strlen(pat)) { if(i==-1||pa... 阅读全文

posted @ 2014-11-09 00:39 kangbry

冒泡排序
摘要:void sort(int* a, int size){ for (int i = 0; i a[j]) { int t = a[j + 1 ]; a[j + 1] = a[j]; ... 阅读全文

posted @ 2014-11-09 00:22 kangbry

算法复杂度
摘要:算法复杂度分为时间复杂度和空间复杂度。其作用:时间复杂度是指执行算法所需要的计算工作量;而空间复杂度是指执行这个算法所需要的内存空间按数量级递增排列,常见的时间复杂度有:常数阶O(1)对数阶O(log2n)线性阶O(n),线性对数阶O(nlog2n)平方阶O(n^2)立方阶O(n^3)k次方阶O(n... 阅读全文

posted @ 2014-11-08 16:51 kangbry

二叉树遍历
摘要:#include #include #include using namespace std;typedef char DataType;typedef struct BiTNode{ DataType data; struct BiTNode *lchild,*rchild;}BITNode;ty... 阅读全文

posted @ 2014-11-07 00:12 kangbry

hash查找
摘要:#include#include#includeusing namespace std; #define HASHSIZE 7#define NULLKEY -32768 struct HashTable{ int *elem; int count;};void init(HashTable* ha... 阅读全文

posted @ 2014-11-05 22:00 kangbry

堆排序算法
摘要:#include using namespace std; //获取父节点 int Parent(int i) { return i/2; } //获取左孩子 int Left(int i) { return 2*i; } //获取右孩子 int Right(i... 阅读全文

posted @ 2014-11-05 21:43 kangbry

组合排列
摘要:排列: 1. 全排列就是从第一个数字起每个数分别与它后面的数字交换。 2. 去重的全排列就是从第一个数字起每个数分别与它后面非重复出现的数字交换。 3. 将待排列字符排序,然后从小到大找出所有字符,即为其全排列组合:1. 扫描字符串中的一个字符。2. 第一是把这个字符放到组合中去,接下来在剩下的n... 阅读全文

posted @ 2014-05-06 14:48 kangbry

胜败者树者树
摘要:http://blog.csdn.net/sunmenggmail/article/details/7527775 胜者树和败者树都是完全二叉树,是树形选择排序的一种变型。每个叶子结点相当于一个选手,每个中间结点相当于一场比赛,每一层相当于一轮比赛。不同的是,胜者树的中间结点记录的是胜者的标号;而败... 阅读全文

posted @ 2014-05-06 12:40 kangbry 阅读(189) 评论(0) 推荐(0)

导航