POJ 1961
来源:互联网 发布:支付宝网络pos机 编辑:程序博客网 时间:2024/06/06 22:20
升级版的2406,题意:到第i个字符之前,寻找循环节循环的最多次数
Period
Time Limit: 3000MS Memory Limit: 30000KTotal Submissions: 16864 Accepted: 8108
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 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.
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
Source
Southeastern Europe 2004
#include<stdio.h>#include<string.h>int next[1123456];char str[1123456];int n;void get_next(){ next[0]=-1; int i=0; int j=-1; while(i<n) { if(j==-1 || str[i]==str[j]) { i++; j++; next[i]=j; } else { j=next[j]; } }}int main(){ int t=1; while(~scanf("%d",&n) && n) { scanf("%s",str); get_next(); if(t>1) printf("\n"); printf("Test case #%d\n",t++); for(int i=2;i<=n;i++) { if(i%(i-next[i])==0 && i/(i-next[i])!=1) { printf("%d %d\n",i,i/(i-next[i])); } } } return 0;}
0 0
- poj 1961
- POJ 1961
- 【POJ 1961】
- poj 1961
- POJ 1961
- Poj 1961
- POJ 1961
- POJ 1961
- POJ 1961
- poj 1961
- (KMP) poj POJ 1961 Period
- kmp算法练习 poj 1226 poj 1961
- POJ 1961 Period
- poj 1961 Period
- POJ 1961 Period
- poj 1961 Period
- poj 1961(KMP)
- POJ 1961 KMP
- Triangle.NET 使用教程(一)
- linux-cmd
- 基础课1
- C#之希尔排序
- http get post记录
- POJ 1961
- linux使用JMETER进行分布式压力测试
- javascript中使用带有参数的自定义构造函数
- 83. Remove Duplicates from Sorted List(LeetCode)
- [Extjs6]随记-使用h5的placeholder给编辑框添加提示效果
- JavaScript的window.open方法
- java编码、加密
- hdu 3590——PP and QQ
- appsetting 和connectionString 的区别。