HDU 1358 Period(KMP next数组运用)
Period
#include<iostream>
#include<algorithm>
#include<string> using namespace std;
const int maxn = ;
int nex[maxn], n, T = ;
void Getnext(string str, int len)
{
nex[] = -; int k = -;
for (int i = ; i < len; i++) {
while (k > - && str[k + ] != str[i])k = nex[k];
if (str[k + ] == str[i])k++;
nex[i+] = k+;
}
}
int main()
{
ios::sync_with_stdio(false);
while(cin>>n&& n){
T++;
string str;
cin >> str;
Getnext(str, n);
cout << "Test case #" << T << endl;
for (int i = ; i <= n; i++) {
int k = i - nex[i];
if (nex[i] == )continue;
if (i%k == )
cout << i << " " << i / k << endl;
}cout << endl;//不要忘了在输出一个换行!
}
return ;
}
HDU 1358 Period(KMP next数组运用)的更多相关文章
- HDU 1358 Period KMP
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1358 求周期问题,简单KMP—— AC代码: #include <iostream> # ...
- Hdu 1358 Period (KMP 求最小循环节)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1358 题目描述: 给出一个字符串S,输出S的前缀能表达成Ak的所有情况,每种情况输出前缀的结束位置和 ...
- hdu 1358 period KMP入门
Period 题意:一个长为N (2 <= N <= 1 000 000) 的字符串,问前缀串长度为k(k > 1)是否是一个周期串,即k = A...A;若是则按k从小到大的顺序输 ...
- HDU 1358 Period(KMP计算周期)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 题目大意:给你一串字符串,判断字符串的前缀是否由某些字符串多次重复而构成. 也就是,从第1个字母 ...
- hdu 1358 Period(KMP入门题)
Period Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- [HDU 1358]Period[kmp求周期]
题意: 每一个power前缀的周期数(>1). 思路: kmp的next. 每一个前缀都询问一遍. #include <cstring> #include <cstdio> ...
- HDU 1358 Period (kmp求循环节)(经典)
<题目链接> 题目大意: 意思是,从第1个字母到第2字母组成的字符串可由某一周期性的字串(“a”) 的两次组成,也就是aa有两个a组成: 第三行自然就是aabaab可有两个aab组成: 第 ...
- hdu 1358 Period
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 思路:Next数组的用法,在第i个位置上如果有i%(i-Next[i])==0的话最小循环节就是 ...
- hdu 1358:Period(KMP算法,next[]数组的使用)
Period Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
随机推荐
- 如何实现已发布app的自动更新
要实现app的自动更新,做两件事情就可以搞定 1.获取当前手机中的app版本号 我们可以通过查询mainbundle中的获取CFBundleVersion NSDictionary *infoDict ...
- kubernetes1.4新特性:支持sysctl命令
背景介绍 sysctl是一个允许改变正在运行中的Linux系统内核参数的接口.可以通过sysctl修改Linux系统内核中的TCP/IP 堆栈和虚拟内存系统的高级选项,而且不需要重新启动Linux系统 ...
- Python里的堆heapq
实际上,Python没有独立的堆类型,而只有一个包含一些堆操作函数的模块.这个模块名为heapq(其中的q表示队列),默认为小顶堆.Python中没有大顶堆的实现. 常用的函数 函 数 描 述 hea ...
- 简单线性回归(最小二乘法)python实现
简单线性回归(最小二乘法)¶ 0.引入依赖¶ In [7]: import numpy as np import matplotlib.pyplot as plt 1.导入数据¶ In [ ...
- poj 2184 01背包变形【背包dp】
POJ 2184 Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14657 Accepte ...
- c++ 对象池的创建
template <class T> class ObjectPool { public: using DeleterType = std::function<void(T*)> ...
- SGU 101 Domino【欧拉路径】
题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=101 题意: N个多米诺骨牌,每个骨牌左右两侧分别有一个0~6的整数(骨牌可以旋转 ...
- gcc需找头文件路径
`gcc -print-prog-name=cc1plus` -v This command asks gcc which C++ preprocessor it is using, and then ...
- 模板—Hash_map
struct Hash_map { ],nx[]; ];]; inline double &operator [] (int x) { ,i=fi[k]; for(;i&&st ...
- 7-3三个模块 hashlib ,logging,configparser和序列化
一 hashlib 主要用于字符串加密 1 import hashlib md5obj=hashlib.md5() # 实例化一个md5摘要算法的对象 md5obj.update('alex3714' ...