hdu 1358 Period (kmp扩展)
来源:互联网 发布:sql从入门到精通的书籍 编辑:程序博客网 时间:2024/06/04 20:02
题意:
给出一个串,找出这个串中所有满足是循环串的前缀子串,并且输出位子和循环周期。
题解:
最小循环节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;}/**51100100000*/
0 0
- 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
- 【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
- hdu 1358 Period(kmp)
- HDU-1358 Period (kmp)
- HDU 1358 Period kmp
- hdu 1358 Period (KMP)
- linux 磁盘挂载
- 网络流学习笔记
- 【IOS】无缝桥接
- hdu-1213 How Many Tables
- Juno: 字体缩放
- hdu 1358 Period (kmp扩展)
- 创建型模式之Prototype
- cocos2d-x Sprite精灵对象创建方法
- mapreduce来清洗数据生成RCFile
- UVa 1611 - Crane(构造法)
- hdu 4535 吉哥系列故事——礼尚往来
- iframe 的缓存文件及解决方法以及 jquery deffered.then() 方法的使用
- NFS挂载中遇到的 svc: failed to register lockdv1 RPC service (errno 111).(connection refused)
- get和post请求数据