博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1961 Period(KMP训练指南例题)
阅读量:4708 次
发布时间:2019-06-10

本文共 1556 字,大约阅读时间需要 5 分钟。

Period
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 11356   Accepted: 5279

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 A
K ,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.

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

题意

给你一个字符串。叫你依次输出输出该串长度为i的前缀(如果该前缀可以由重复子串得到)的长度。产生该前缀所需的最大重复次数。

思路:

见训练指南。

详细见代码:

 

#include 
#include
#include
using namespace std;const int maxn=1000100;int f[maxn];char txt[maxn];void getf(char *p){ int i,j,m=strlen(p); f[0]=f[1]=0; for(i=1;i

 

 

转载于:https://www.cnblogs.com/pangblog/p/3325088.html

你可能感兴趣的文章
Servlet的生命周期
查看>>
十种经典排序算法
查看>>
js中的apply与call的用法与区别
查看>>
标准C程序设计七---102
查看>>
[开发笔记]-获取天气数据接口
查看>>
北京地铁月度消费总金额计算(Python版)
查看>>
nginx+tomcat配置https
查看>>
[hadoop]备份
查看>>
Redis 哈希(Hash)
查看>>
微享:快速分享网页到新浪微博
查看>>
7. 信号的处理问题
查看>>
SDN简介
查看>>
xshell远程终端操作Ubuntu server安装LAMP环境之最详细笔记之二PHP开发环境配置
查看>>
Ionic实战 自动升级APP(Android版)
查看>>
C#中的委托和事件(续)
查看>>
python--MySql
查看>>
机器学习 - pycharm, pyspark, spark集成篇
查看>>
mysql explain 中key_len的计算
查看>>
实验一
查看>>
Linux内核--网络栈实现分析(九)--传输层之UDP协议(下)
查看>>