摘要: 不得不说下, 这题和2406 几乎是用同样的方法来做。只要这题再枚举下每一个点就可以了。 判断是从第二个字符开始的。 还要判断该字符的下一个next[] 不是0 就可以了View Code #include<stdio.h>#include<string.h>#define maxn 1000008int next[maxn];char sift[maxn];int len;void get_next(){ int i = 0, j = -1; next[0] = -1; while (i <= len) { if (j == -1 || sift[j] ... 阅读全文
posted @ 2012-04-11 01:29 CY_K_YC 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 这题只是简单的KMP 算法。 只是有一点需要注意的就是当最后一个的大小是 len % (len - next[len])不够除的时候, 要直接判断是1, 不用继续计算。其他的就是裸的求nextView Code #include<stdio.h>#include<string.h>#define maxn 1000008int next[maxn];char sift[maxn];int n;void get_next(){ int len = strlen(sift); int i = 0, j = -1; next[0] = -1; while (i <= l 阅读全文
posted @ 2012-04-11 00:57 CY_K_YC 阅读(123) 评论(0) 推荐(0) 编辑