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 ...
随机推荐
- python学习笔记(二):python数据类型
上一篇博客写了python的入门和简单流程控制,这次写python的数据类型和各种数据类型的内置方法.一.数据类型是什么鬼?计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各 ...
- 2015.3.3 VC6调用dll
用VC新建一对话框工程,在一按钮点击事件中添加如下代码: typedef void (WINAPI * TESTDLL)(); HINSTANCE hmod; hmod = ::LoadLibrary ...
- 如何将DevExpress的Gridcontrol导出到Excel
private void simpleButton1_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new S ...
- CSS——盒子模型
一.盒子模型: 模型如下: 如图:盒子模型包括:margin.padding.border.content四部分. margin:外边距,透明,能够显示父级的背景颜色等.表示元素与元素之间的间隔或者说 ...
- C++ 私有构造函数的作用
很多情况下要求当前的程序中只有一个object.例如一个程序只有一个和数据库的连接,只有一个鼠标的object.通常我们都将构造函数的声明置于public区段,假如我们将 其放入private区段中会 ...
- mysql sequelize 聚合
User.findAll({attributes: [[sequelize.fn('COUNT', sequelize.col('*')), 'email']],raw: true }).then(f ...
- ReactNative http网络通讯
安装 fetch npm install whatwg-fetch --save 1.fetch的Get方式通讯 async sendGet(){ let response = await fetch ...
- 4、Brief primer and lexicon for PacBio SMRT sequencing
转载:http://pacbiofileformats.readthedocs.io/en/5.1/Primer.html 转载:http://pacbiofileformats.readthedoc ...
- 1054D&EZOJ #93 Changing Array
传送门 分析 我们可以对一个数列求前缀和,如果pre[l]=pre[r]则我们可以知道区间[l,r]一定不合法 于是我们就要让不合法的区间尽量少 我们知道对于一个数$x$,他只受x和$(2^k-1)$ ...
- 安装visual_Paradigm,时序图的应用
此安装包已经上传到sunny的百度网盘. 删除,即,右击别的地方,然后,选择delete即可. 拖箭头,拖到某个实体上,再松开,会自动连线. 很好的一款画图工具.