06 2013 档案

摘要:亲戚题:已知a和b是亲戚,a和c是亲戚,则可以判断出b和c也是亲戚。将多个集合合并成没有交集的集合。 1 #include <iostream> 2 using namespace std; 3 4 int N, M, Q; 5 int pre[20000], rak[20000]; 6 7 void MakeSet(int x) 8 { 9 pre[x] = -1;10 rak[x] = 0;11 }12 13 int FindSet(int x)14 {15 int r = x, q;16 while (pre[r] != -1)17 r... 阅读全文

posted @ 2013-06-20 11:02 月moon鸟 阅读(170) 评论(0) 推荐(0)

摘要:Trie,又称单词查找树或键树,是一种树形结构,是一种哈希树的变种。利用字符串的公共前缀来降低查询时间的开销以达到提高效率的目的。可以统计词频或是判断是否是前缀。1000万的广告库关键词,来一个查询词,找出是查询词子集的关键词集合。 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 5 #define MAX 256 6 #define MAXLEN 256 7 8 typedef struct _TrieNode 9 {10 int count;11 struct _Tri 阅读全文

posted @ 2013-06-20 10:50 月moon鸟 阅读(236) 评论(0) 推荐(0)

摘要:自己写一个函数实现类似库函数itoa的功能,将整数转化为字符串。整数转汉字,表示货币量。1、代码: 1 char *IntToStr(int num, char str[]) 2 { 3 int i = 0, j = 0; 4 char temp[100]; 5 while(num) 6 { 7 temp[i] = num % 10 + '0'; //取模运算得到从后往前的每一个数字变成字符 8 num = num / 10; 9 i++;10 }11 temp[i] = 0; //字符串... 阅读全文

posted @ 2013-06-08 20:28 月moon鸟 阅读(761) 评论(0) 推荐(0)

摘要:前序,中序,后序遍历的非递归实现。层次遍历,从上到下或从下到上,从左到右或从右到左,只输出叶子节点,只输出某一层等等。1、代码: 1 void PreOrder(BinaryTreeNode* root) 2 { 3 if (!root) return; 4 stack<BinaryTreeNode*> nodes; 5 while (root != NULL || !nodes.empty()) 6 { 7 if (root != NULL) 8 { 9 cout << root->m_nValue <<... 阅读全文

posted @ 2013-06-07 21:00 月moon鸟 阅读(177) 评论(0) 推荐(0)

导航