hdu 1358 Period
来源:互联网 发布:淘宝发布宝贝预览 编辑:程序博客网 时间:2024/06/18 14:14
点击打开链接
Period
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9581 Accepted Submission(s): 4597
Problem Description
For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 <= i <= N) we want to know the largest K > 1 (if there is one) such that the prefix of S with length i can be written as AK , that is A concatenated K times, for some string A. Of course, we also want to know the period K.
Input
The input file consists of several test cases. Each test case consists of two lines. The first one contains N (2 <= N <= 1 000 000) – the size of the string S. The second line contains the string S. The input file ends with a line, having the number zero on it.
Output
For each test case, output “Test case #” and the consecutive test case number on a single line; then, for each prefix with length i that has a period K > 1, output the prefix size i and the period K separated by a single space; the prefix sizes must be in increasing order. Print a blank line after each test case.
Sample Input
3aaa12aabaabaabaab0
Sample Output
Test case #12 23 3Test case #22 26 29 312 4
#include <iostream>#include <cstring>#include <cstdio>const int N=1e6;char mo[N+10];int Next[N+10];int len;using namespace std;void getNext(){Next[0]=-1;int i=0,j=-1;while(i<len){if(j==-1||mo[i]==mo[j]){i++;j++;Next[i]=j;}elsej=Next[j];}}int main(){int k=1;while(scanf("%d",&len),len){scanf("%s",mo);getNext();printf("Test case #%d\n",k++);for(int i=1;i<=len;i++){if(i%(i-Next[i])==0&&i!=i-Next[i])printf("%d %d\n",i,i/(i-Next[i]));}printf("\n");}return 0;}
阅读全文
0 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
- 【JSP开发】利用cookie实现商品浏览记录
- The Counting Problem UVA
- Android性能优化之Ubuntu安装Battery Historian分析电量
- React Native 键盘弹起、收起动画与输入框的动作(几乎)完美同步
- scala 函数定义格式
- hdu 1358 Period
- JSF中调用js函数方法之一和二
- Eclipse_Properties里报多个黄叹号&Tomcat卡死报错解决&页面500
- 作业1
- 高级软件工程学习心得
- 解释型语言和编译型语言的区别
- 断点续传进度条显示 开始 暂停 结束
- 69. Sqrt(x)
- 单机版hadoop平台搭建