hdu 1358 Period
来源:互联网 发布:南通seo招聘 编辑:程序博客网 时间:2024/06/10 16:38
kmp算法的应用。
kmp算法入门http://billhoo.blog.51cto.com/2337751/411486
字符串偏移量为i-next[i],i为字符串的当前前缀长度。若偏移量能够被前缀长度整除,则该前缀可写为A^B。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;void getNext(char *str,int *next){int len = strlen(str);int j = 0;next[1] = 0;for(int i = 2;i<len+1;i++){while(j>0&&str[j]!=str[i-1]){j = next[j];}if(str[j]==str[i-1])j++;next[i] = j;}}char str[1000005];int next[1000005];int main(){int n,k=1;while(scanf("%d",&n)&&n){scanf("%s",str);getNext(str,next);printf("Test case #%d\n",k++);for(int i = 1;i<=n;i++){int tmp = i-next[i];if(tmp&&i%tmp==0){if(i/tmp>1)printf("%d %d\n",i,i/tmp);}}printf("\n");}return 0;}
- HDU 1358 Period (KMP)
- HDU 1358 Period
- hdu 1358 Period
- hdu 1358 Period
- hdu 1358 Period
- HDU 1358 Period KMP
- hdu 1358 Period
- hdu 1358 Period KMP
- hdu 1358 Period(KMP)
- HDU 1358 Period KMP
- hdu 1358 Period
- hdu 1358 Period
- 【HDU】1358 Period KMP
- HDU - 1358 Period
- HDU 1358 Period (KMP)
- HDU 1358 Period
- hdu 1358 Period
- HDU 1358 Period
- HDU 1213 How Many Tables
- or1200下Raw-OS学习(仿真环境篇)
- OpenVPN中的几个和连接相关的Timer解析
- 数据结构练习题---先序遍历二叉树
- html5 拖放操作集锦
- hdu 1358 Period
- 数据结构练习题---后序遍历二叉树
- do...while(0)的妙用
- ab测试tomcat并发性能(测试BIO与NIO差别)(一)
- BFS+剪枝--hdoj1195(不错)
- windows8和windowsserver2012不联网安装.net3.5(包括2.0和3.0)
- ccny_vision compiling on ros-fuerte
- 最短路径+Dijkstra+打印路径
- 三十分钟掌握STL