Period
Time Limit: 3000MS   Memory Limit: 30000K
     

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.

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

3
aaa
12
aabaabaabaab
0

Sample Output

Test case #1
2 2
3 3 Test case #2
2 2
6 2
9 3
12 4

Source

题目大意:对于字符串的每个位置i(i>1),若到i,i之前有循环节,输出i及其长度
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n,t;
char s[];
int f[];
void getnext()
{
for(int i=;i<n;i++)
{
int j=f[i];
while(j&&s[i]!=s[j]) j=f[j];
f[i+]= s[i]==s[j] ? j+:;
if(i>=&&f[i+])
{
int a=i+-f[i+];
if((i+)%a==) printf("%d %d\n",i+,(i+)/a);
}
}
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
t++;
if(!n) return ;
scanf("%s",s);
memset(f,,sizeof(f));
printf("Test case #%d\n",t);
getnext();
printf("\n");
}
}

poj 1961 Period的更多相关文章

  1. KMP POJ 1961 Period

    题目传送门 /* 题意:求一个串重复出现(>1)的位置 KMP:这简直和POJ_2406没啥区别 */ /******************************************** ...

  2. POJ 1961 Period( KMP )*

    Period Time Limit: 3000MSMemory Limit: 30000K Total Submissions: 12089Accepted: 5656 Description For ...

  3. POJ 1961 Period(KMP)

    http://poj.org/problem?id=1961 题意 :给你一个字符串,让你输出到第几个字符时,循环结的个数. 思路 :这个题和2409差不多,稍微修改一下,加一个循环就行了,用的也是K ...

  4. POJ 1961 Period KMP算法next数组的应用

    题目: http://poj.org/problem?id=1961 很好的题,但是不容易理解. 因为当kmp失配时,i = next[i],所以错位部分就是i - next[i],当s[0]...s ...

  5. (简单) POJ 1961 Period,扩展KMP。

    Description For each prefix of a given string S with N characters (each character has an ASCII code ...

  6. poj 1961 Period 【KMP-next前缀数组的应用】

    题目地址:http://poj.org/problem?id=1961 Sample Input 3 aaa 12 aabaabaabaab 0 Sample Output Test case #1 ...

  7. KMP——POJ-3461 Oulipo && POJ-2752 Seek the Name, Seek the Fame && POJ-2406 Power Strings && POJ—1961 Period

    首先先讲一下KMP算法作用: KMP就是来求在给出的一串字符(我们把它放在str字符数组里面)中求另外一个比str数组短的字符数组(我们叫它为ptr)在str中的出现位置或者是次数 这个出现的次数是可 ...

  8. poj 1961 Period【求前缀的长度,以及其中最小循环节的循环次数】

    Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 14653   Accepted: 6965 Descripti ...

  9. poj 1961 Period(KMP训练指南例题)

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

随机推荐

  1. 软工1816 · Beta冲刺(6/7)

    团队信息 队名:爸爸饿了 组长博客:here 作业博客:here 组员情况 组员1(组长):王彬 过去两天完成了哪些任务 推进Web端完成开发 推进修改一些后端接口的逻辑 着手制作视频 接下来的计划 ...

  2. ubuntu16.04+pycharm+默认文件头注释

    安装 1.sudo gedit /etc/hosts 2.最后一行添加 0.0.0.0 account.jetbrains.com 3.从 http://idea.lanyus.com/ 中获取激活码 ...

  3. “吃神么,买神么”的第一个Sprint计划(第四天)

    “吃神么,买神么”项目Sprint计划 ——5.24  星期日(第四天)立会内容与进度 摘要:logo做出来了,但是在立会展示时遭到反对,不合格,重新设计.(附上失败的logo图) 目前搜索栏出来了, ...

  4. NABCD(网上投票系统)

    网上投票系统 N(need) 投票这件事情,在所有事情上都可能用得到,在互联网的影响下,投票的范围变得越来越广,比如在商业的里,往往要做市场分析,那么在互联网这个大的前提下,用网上投票系统来获取用户的 ...

  5. contos7忘记root密码怎么办

    首先在这个界面按"e"键 然后呢就会进入到如下图所示的界面,在LANG=zh_CN.UTF8的后面加上 init=/bin/sh, 再按 [ Ctrl + X ] 进入'单用户模式 ...

  6. ansible的简单使用

    环境搭建跳过(暂无,这个以后再学习学习,不要在意这些细节) 首先,在环境搭建好后,用两台虚机来做测试,一台192.168.181.130做测试机,一台192.168.181.131为批量处理服务器 编 ...

  7. Beta阶段——第二篇 Scrum 冲刺博客

    i. 提供当天站立式会议照片一张: ii. 每个人的工作 (有work item 的ID) (1) 昨天已完成的工作: 账单收支分明,剩余舍费关联成功 (2) 今天计划完成的工作: 账单删除功能,排序 ...

  8. windows下python3.6安装pycryto or crypto or pycryptodome与使用

    pycrypto,pycrytodome和crypto是一个东西,在很久以前,crypto在python上面的名字是pycrypto它是一个第三方库,但是已经停止更新三年了,所以不建议安装这个库: w ...

  9. 关于request对象的parameter和attribute

    request对象的parameter相关method用于浏览器和服务之间传递数据,且是单向的,只能由浏览器写数据,request读数据,所以只有 String getParameter(String ...

  10. ajax异步请求loading

    1.找到一张loading图片 2.添加样式 <style> .loadingWrap{ position:fixed; top:; left:; width:100%; height:1 ...