文章分类 -  hash、Trie、Map、Set

摘要:这题我不释放trie的空间,结果MLE了一次。。。#include <stdio.h>#include <string.h>#define MAXKIND 129#define MAXN 1005#define MAXLEN1 55#define MAXLEN 2000005#define MAXQSIZE 500005typedef struct TNode{ TNode... 阅读全文
posted @ 2010-09-04 21:55 菜到不得鸟 阅读(392) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <string.h>#define MAXKIND 129#define MAXN 505#define MAXLEN 10005#define MAXQSIZE 500005typedef struct TNode{ TNode() { id=-1; fail=NULL; memset(next,0,sizeof(ne... 阅读全文
posted @ 2010-09-04 19:01 菜到不得鸟 阅读(253) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char in[50005][100];char *ans[50005];struct TNode{ TNode() { end=0; memset(next,0,sizeof(next)); } bool e... 阅读全文
posted @ 2010-08-29 20:47 菜到不得鸟 阅读(167) 评论(0) 推荐(0)
摘要://简单字典树,520K,16MS#include <stdio.h>#include <string.h>#define MAXL 1001#define MAXLEN 22typedef struct TNode{ TNode() { cnt=0; memset(next,0,sizeof(next)); } int cnt; TNode *next[26];}*Tri... 阅读全文
posted @ 2010-08-25 23:39 菜到不得鸟 阅读(113) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <vector>#include <algorithm>using namespace std;#define MAXLEN 22#define MAXSON 28typedef struct TNode{ T... 阅读全文
posted @ 2010-08-25 22:58 菜到不得鸟 阅读(286) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <string.h>#define MAXTSIZE 100000#define MAXLEN 11typedef struct TNode{ TNode() { end=false; memset(next,0,sizeof(next)); } bool end; TNode *next[2];}*Trie;TNode... 阅读全文
posted @ 2010-08-25 20:25 菜到不得鸟 阅读(178) 评论(0) 推荐(0)
摘要://这题用动态数组的话,会TLE。用静态数组125MS(也可先排序再一一比较前缀):#include <stdio.h>#include <string.h>#define MAXTSIZE 100000#define MAXLEN 15typedef struct TNode{ TNode() { end=false; memset(next,0,sizeof(next)... 阅读全文
posted @ 2010-08-25 20:13 菜到不得鸟 阅读(137) 评论(0) 推荐(0)
摘要:建立好待搜索的字符串,然后八方向遍历那个字母框#include <stdio.h>#include <string.h>#include <stdlib.h>#define MAXSIZE 1003typedef struct TrieNode{ TrieNode() { end=-1; memset(next,NULL,sizeof(next)); } int... 阅读全文
posted @ 2010-08-25 19:22 菜到不得鸟 阅读(121) 评论(0) 推荐(0)
摘要:和pku1386 hdu1116 Play on Words差不多,不同的是这题的木棒是无向的,即是无向图。可以hash也可以用字典树,个人喜欢hash,够快,不知道map会不会超时#include <cstdio>#include <cstring>#include <iostream>using namespace std;#define MAXSIZE 5... 阅读全文
posted @ 2010-08-19 11:53 菜到不得鸟 阅读(233) 评论(0) 推荐(0)
摘要://法1 map 640MS#include <cstdio>#include <string>#include <map>using namespace std;map<string,int> level;string str;int main(){ int n; while(scanf("%d",&n)!=EOF) { level.cle... 阅读全文
posted @ 2010-08-18 14:45 菜到不得鸟 阅读(180) 评论(0) 推荐(0)
摘要:水题,用map做最爽//法1 直接模拟 0MS#include <iostream>using namespace std;int main(){ char str[1001][16]; int ct[1001]; int n,i,j,index; //因为不是每次输入一个颜色都是新的,只有输入新颜色时才需要增加index--颜色的种类数 while(scanf("%d",&n... 阅读全文
posted @ 2010-08-18 14:41 菜到不得鸟 阅读(229) 评论(0) 推荐(0)
摘要:这题是不区分大小写的#include <stdio.h>#include <string.h>#include <ctype.h>#include <stdlib.h>#include <string>#include <map>#include <iostream>using namespace std;#def... 阅读全文
posted @ 2010-08-18 14:33 菜到不得鸟 阅读(273) 评论(0) 推荐(0)
摘要:各种字符串Hash函数比较常用的字符串Hash函数还有ELFHash,APHash等等,都是十分简单有效的方法。这些函数使用位运算使得每一个字符都对最后的函数值产生影响。另外还有以MD5和SHA1为代表的杂凑函数,这些函数几乎不可能找到碰撞。常用字符串哈希函数有BKDRHash,APHash,DJBHash,JSHash,RSHash,SDBMHash,PJWHash,ELFHash等等。对于以上... 阅读全文
posted @ 2010-08-18 14:33 菜到不得鸟 阅读(1018) 评论(0) 推荐(0)
摘要:47MS,用BKDRHash+链表解决冲突#include <stdio.h>#include <string.h>#define MAX1 50003#define MAX2 200typedef struct node{ int ind; node *next;} node;node newnode[MAX1];int newn;typedef struct hashn... 阅读全文
posted @ 2010-08-18 14:31 菜到不得鸟 阅读(237) 评论(0) 推荐(0)