HDU 1358 Period 求前缀长度和出现次数(KMP的next数组的使用)
Period
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12428 Accepted Submission(s): 5825
aaa
12
aabaabaabaab
0
2 2
3 3
Test case #2
2 2
6 2
9 3
12 4
给一个字符串,从第二个字符开始,让你判断前面字符串是否具有周期性,然后输出此位置和最大周期数。(周期要大于一)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<memory>
using namespace std;
char wenben[];
int next1[];
void getnext1(char* s,int* next1,int m)
{
next1[]=;
next1[]=;
for(int i=;i<m;i++)
{
int j=next1[i];
while(j&&s[i]!=s[j])
j=next1[j];
if(s[i]==s[j])
next1[i+]=j+;
else
next1[i+]=;
}
}
int main()
{
int L;
int t=;
while(~scanf("%d",&L))
{
if(L==)
break;
scanf("%s",wenben);
getnext1(wenben,next1,L);
for(int i=;i<L;i++)
printf("i=%d->%d ",i,next1[i]);
printf("\n");
printf("Test case #%d\n",t++);
for(int i=;i<=L;i++)
{
int k=i-(next1[i]);
if(k!=i&&(i)%k==)
printf("%d %d\n",i,i/k);
}
printf("\n");
}
return ;
}
HDU 1358 Period 求前缀长度和出现次数(KMP的next数组的使用)的更多相关文章
- hdu 1358 Period (KMP求循环次数)
Problem - 1358 KMP求循环节次数.题意是,给出一个长度为n的字符串,要求求出循环节数大于1的所有前缀.可以直接用KMP的方法判断是否有完整的k个循环节,同时计算出当前前缀的循环节的个数 ...
- [HDU 1358]Period[kmp求周期]
题意: 每一个power前缀的周期数(>1). 思路: kmp的next. 每一个前缀都询问一遍. #include <cstring> #include <cstdio> ...
- hdu 1358 period KMP入门
Period 题意:一个长为N (2 <= N <= 1 000 000) 的字符串,问前缀串长度为k(k > 1)是否是一个周期串,即k = A...A;若是则按k从小到大的顺序输 ...
- 【HDU 1358 Period】
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 3746 - Cyclic Nacklace & HDU 1358 - Period - [KMP求最小循环节]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- KMP + 求最小循环节 --- HDU 1358 Period
Period Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=1358 Mean: 给你一个字符串,让你从第二个字符开始判断当前长度 ...
- Hdu 1358 Period (KMP 求最小循环节)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1358 题目描述: 给出一个字符串S,输出S的前缀能表达成Ak的所有情况,每种情况输出前缀的结束位置和 ...
- HDU 1358 Period (kmp求循环节)(经典)
<题目链接> 题目大意: 意思是,从第1个字母到第2字母组成的字符串可由某一周期性的字串(“a”) 的两次组成,也就是aa有两个a组成: 第三行自然就是aabaab可有两个aab组成: 第 ...
- hdu 1358 Period(kmp求一个串的重复子串)
题意:统计单串中从某个位置以前有多少重复的串 思路:kmp模板 #include<iostream> #include<stdio.h> #include<string. ...
随机推荐
- Windows 环境下 NodeJs 开发 Log
安装 NodeJs, npm. 环境变量配置. 1, Grunt 安装 : npm install -g grunt-clinpm install -g grunt package.json { & ...
- How To Secure Apache with Let's Encrypt on Ubuntu (Free SSL)
Introduction This tutorial will show you how to set up a TLS/SSL certificate from Let's Encrypt on a ...
- C++多线程编程(教程+Demo)
下载地址:C++多线程编程(教程+Demo) Win32 SDK函数支持进行多线程的程序设计,并提供了操作系统原理中的各种同步.互斥和临界区等操作.Visual C++ 6.0中,使用MFC类库也实现 ...
- 上海ctf2017 pwn100 && pwn200
前言 分析的 idb 文件在这: https://gitee.com/hac425/blog_data/tree/master/shanghaictf pwn100 程序是一个经典的 堆管理程序,基本 ...
- Python爬虫教程-04-response简介
Spider-04-response简介 本小节介绍urlopen的返回对象,和简单调试方法 案例v3 研究request的返回值,输出返回值类型,打印内容 geturl:返回请求对象的url inf ...
- centos下安装ipython(minglnghang命令行)
下载文件 wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate 执行安装 python get-pip.py 这就安装好了 ...
- 毕向东_Java基础视频教程第20天_IO流(15~17)
第20天-15-IO流(打印输出流) 打印输出流:PrintWriter与PrintStream 两者的区别:Since JDK 1.4 it's possible to specify the ch ...
- springboot中filter的配置和顺序执行
项目结构 springboot版本 <parent> <groupId>org.springframework.boot</groupId> <artifac ...
- python中的特殊数据类型
一.python中的特殊数据类型 对于python,一切事物都是对象,对象基于类创建.像是“wangming”,38,[11,12,22]均可以视为对象,并且是根据不同的类生成的对象. 参照:http ...
- angular based app开发流程
整理user story mock UI,生成满足上述user story的原型界面 根据上述UI,整理出data model(适用于后端和angular的数据模型) 后端CRUD开发,形成REST ...