kuangbin专题十六 KMP&&扩展KMP HDU1358 Period
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.
OutputFor 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 知道循环节怎么求,然后从头到尾处理Next[i]就可以了
#include<stdio.h>
#include<string.h>
int Next[],n;
char p[]; void prekmp() {
int i,j;
j=Next[]=-;
i=;
while(i<n) {
while(j!=-&&p[i]!=p[j]) j=Next[j];
Next[++i]=++j;
}
} int main() {
int Case=;
//freopen("out","r",stdin);
while(~scanf("%d",&n)) {
if(n==) break;
scanf("%s",p);
prekmp();
printf("Test case #%d\n",++Case);
for(int i=;i<=n;i++) {
int l=i-Next[i];
// printf("%d***%d\n",l,Next[i]);
if(i%l==&&i/l>) printf("%d %d\n",i,i/l);
}
printf("\n");
}
}
kuangbin专题十六 KMP&&扩展KMP HDU1358 Period的更多相关文章
- kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...
- kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...
- kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...
- kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans
The Genographic Project is a research partnership between IBM and The National Geographic Society th ...
- kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...
- kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条
一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...
- kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence
Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...
随机推荐
- paramiko连接方式
链接方法: 方式一: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh. ...
- [Python Study Notes]pynput实现对键盘控制与监控
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- oracle --(二)分区(extent)
基本关系:数据库---表空间---数据段---分区---数据块 一.分区(extent)分区extent是比数据块大一级的存储结构,是几个逻辑上相邻的data block的组合.我们知道,物理存储通常 ...
- 使用Java建立聊天客户端
---------------siwuxie095 关于 聊天服务器,详见本人博客的分类:来一杯Java, 里面的 使用ServerSocket ...
- 39、count_rpkm_fpkm_TPM
参考:https://f1000research.com/articles/4-1521/v1 https://www.biostars.org/p/171766/ http://www.rna-se ...
- CH24C 逃不掉的路
edcc缩点之后跳倍增lca 丢个edcc缩点模板 Code: #include <cstdio> #include <cstring> using namespace std ...
- JDBC方式从数据库中查询数据并显示
1.创建数据库表myuser DROP TABLE IF EXISTS `myuser`; CREATE TABLE `myuser` ( `) NOT NULL COMMENT '姓名', `id` ...
- 【IMOOC学习笔记】多种多样的App主界面Tab实现方法(二)
Fragment实现Tab 首先把activity_main.xml 文件中的ViewPager标签改成Fragment标签 <FrameLayout android:id="@+id ...
- adb 无法调试的问题,ADB server didn't ACK,* failed to start daemon *
The connection to adb is down, and a severe error has occured. You must restart adb and Eclipse. Ple ...
- asp 控件定时器 局部刷新
<asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePan ...