hdu 1358 Period (kmp扩展)
2015-02-12 19:33
405 查看
题意:
给出一个串,找出这个串中所有满足是循环串的前缀子串,并且输出位子和循环周期。
题解:
最小循环节i-next[i],水过。
给出一个串,找出这个串中所有满足是循环串的前缀子串,并且输出位子和循环周期。
题解:
最小循环节i-next[i],水过。
#include<iostream> #include<math.h> #include<stdio.h> #include<algorithm> #include<string.h> #include<vector> #include<map> using namespace std; //typedef long long lld; const int oo=0x3f3f3f3f; //const lld OO=1LL<<61; const int MOD=10007; const int maxn=1000005; char str[maxn]; int next[maxn]; void get_next(int len) { int i=0;next[i]=-1; int j=-1; while(i<len) { if(j==-1||str[i]==str[j]) { i++;j++; next[i]=j; } else j=next[j]; } } int main() { int n,cas=1; while(scanf("%d",&n)!=EOF) { if(n==0)break; scanf("%s",str); get_next(n); printf("Test case #%d\n",cas++); for(int i=2;i<=n;i++) { int cir=i-next[i]; if(cir!=i&&i%cir==0) { printf("%d %d\n",i,i/cir); } } puts(""); } return 0; } /** 5 11001 00000 */
相关文章推荐
- [HDU 1358] Period KMP扩展
- hdu 1358 Period(KMP)
- HDU 1358 Period【KMP】
- HDU 1358 Period (KMP)
- HDU 1358 Period KMP
- hdu 1358 Period(KMP)
- hdu 1358 Period(KMP循环)
- 【KMP(循环节)】poj 2406 Power Strings(外:hdu 1358 Period)
- 【HDU】1358 Period KMP
- poj1961 & hdu 1358 Period(KMP)
- HDU 1358 Period KMP
- hdu 1358 period 求循环节 KMP
- [HDU 1358]Period[kmp求周期]
- HDU 1358 Period(KMP)
- HDU 1358 Period 求周期串(kmp)
- Period hdu 1358 KMP的使用
- [KMP-循环节问题]HDU 1358 period
- [HDU 1358]Period[kmp求周期]
- hdu 1358 Period(KMP 循环节)
- hdu 1358 Period (KMP)