Fork me on GitHub

随笔分类 -  【字符串算法 Strings】

摘要:题意:多个模板串,一个文本串,求出那些模板串在文本串中出现次数最多。解法:AC自动机入门模板题。代码:#include #include #include #include #include #include #include #include #include #include #define M... 阅读全文
posted @ 2015-03-05 23:04 whatbeg 阅读(175) 评论(0) 推荐(0)
摘要:1.POJ 3450 Coporate Identity这两题的解法都是枚举子串,然后匹配,像这种题目以后可以不用KMP来做,直接字符串自带的strstr函数搞定,如果字符串未出现,该函数返回NULL。下面贴出其比较。代码:(KMP版)(1360ms 888KB)#include #include #include #include #include using namespace std;#define N 4007char ans[203],str[203];char ss[N][203],tt[203];int next[203];void getnext(char *ss){ i... 阅读全文
posted @ 2014-02-22 14:26 whatbeg 阅读(321) 评论(0) 推荐(0)
摘要:A. Codeforces 92A Chips签到题。。#include #include #include #include #include using namespace std;#define N 10007int a[55];int main(){ int n,m,i; whi... 阅读全文
posted @ 2014-02-20 13:51 whatbeg 阅读(355) 评论(0) 推荐(0)
摘要:1.HDU 1711 Number Sequence代码:#include #include #include #include #include using namespace std;#define N 10007int a[1000007],b[N],next[N];int n,m;void getnext(){ next[0] = -1; int i = 0,j = -1; while(i#include #include #include #include using namespace std;#define N 10007int a[1000007],b[N],... 阅读全文
posted @ 2014-02-19 15:00 whatbeg 阅读(194) 评论(0) 推荐(0)
摘要:字典树较简单题,无需维护标记,注意细节即可。代码:#include #include #include using namespace std;#define N 100027struct node{ node *next[2];}*root;char ss[10][13];node *create(){ node *p; p = (node *)malloc(sizeof(node)); for(int i=0;inext[i] = NULL; return p;}void release(node *p){ for(int i=0;inext[i] !=... 阅读全文
posted @ 2014-02-12 16:33 whatbeg 阅读(220) 评论(0) 推荐(0)
摘要:较简单字典树,每输入一对字符串,前一个放在字典(数组)中,后一个插入字典树中,并将其最终的flag赋为前一个在数组中的下标,再就好找了。输入的处理方法要注意一下。 代码:#include #include #include #include #include #include #include #include using namespace std;#define N 100027struct node{ int flag; node *next[26];}*root;char dic[N][11];node *create(){ node *p; p = (nod... 阅读全文
posted @ 2014-02-11 16:47 whatbeg 阅读(209) 评论(0) 推荐(0)
摘要:字典树又一基本题代码:#include #include #include #include #include using namespace std;#define N 1027struct node{ int count; node *next[30];}*root;char ss[13];node *create(){ node *p; p = (node *)malloc(sizeof(node)); p->count = 1; for(int i=0;inext[i] = NULL; return p;}void release(node *... 阅读全文
posted @ 2014-02-03 14:29 whatbeg 阅读(218) 评论(0) 推荐(0)
摘要:字典树基本题。代码:#include #include #include #include #include #include using namespace std;#define N 1027struct node{ int count; node *next[30];}*root;char ss[N][30];node *create(){ node *p; p = (node *)malloc(sizeof(node)); p->count = 1; for(int i=0;inext[i] = NULL; return p;}void rel... 阅读全文
posted @ 2014-02-03 14:25 whatbeg 阅读(249) 评论(0) 推荐(0)