摘要: /* 基本题意:给一个字符串,如果在前 i 位置处满足连续循环A^K(A:单位循环段, K:循环个数),则输出i和K 这题跟pku 2406差不多 YY : kmp 保存 next[i],如果满足 i能被单位长度(i - next[i])整除,说明 (i - next[i])是单位循环段A,i /(i - next[i])也就是K。 举两个例子应该就能理解 例一: i : 12345678 字符串 : abababab next[i]: 00123456 这个例子假如当i等于8时,next[i] = 6; K也就是4,如果你有“ 你只是看 了后面[next[i]+1,i ] 这一段,不能代表全 阅读全文
posted @ 2011-02-19 20:18 kfinder 阅读(368) 评论(0) 推荐(0) 编辑
摘要: /* 题意:给两个字符串a,s,判断a在s里出现的个数*/#include <stdio.h>#include <string.h>int next[10005];char a[10005];char s[1000005];int n,len_a,len_s;void Get_Next(){ a[0] = '#';//因为是a+1,如果a[0]不存在,那strlen(a) = 0 ; !!!!!!!!!!! len_a = strlen(a); len_s = strlen(s); next[1] = 0; int j = 0; for(int i=2; 阅读全文
posted @ 2011-02-19 18:58 kfinder 阅读(524) 评论(0) 推荐(0) 编辑