UVA - 1328 Period(循环节kmp)
https://vjudge.net/problem/UVA-1328
题意
求每个前缀的最小循环节,要求至少循环两次且为完整的。
分析
求next数组,i-next[i]即为前缀i的最小循环节,再判断一下限制条件即可。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
//#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
#define pi acos(-1)
//const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + ;
const int maxm = 4e5 +;
const int mod = ;
const int sigma_size = ; char s[maxn];
int f[maxn];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("input.txt", "w", stdout);
#endif
int cas=;
int T;
int n;
while(~scanf("%d",&n)&&n){
scanf("%s",s);
f[]=f[]=;
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+:;
}
printf("Test case #%d\n",cas++);
for(int i=;i<=n;i++){
if(f[i]>&&i%(i-f[i])==)
printf("%d %d\n",i,i/(i-f[i]));
}
printf("\n");
}
return ;
}
UVA - 1328 Period(循环节kmp)的更多相关文章
- UVa 1328 Period
数据范围较大,故用KMP求循环节 之后由小到大枚举长度范围,若该长度下有循环节就输出答案 还要注意输出格式.之前测试时候连着一串presentation error也是悲伤 #include<b ...
- Colossal Fibonacci Numbers! UVA 11582 寻找循环节
/** 题目:Colossal Fibonacci Numbers! UVA 11582 链接:https://vjudge.net/problem/UVA-11582 题意:f[0] = 1, f[ ...
- UVA 1328 - Period KMP
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36131 题意:给出一个长度为n的字符串,要求找到一些i,满足说从1 ...
- Period---hdu1358(循环节 kmp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 题意 :求给你个串,前i位子串由某个字符串重复k次得到,求所有的i和k(k>1); 例如: ...
- UVAlive 3026 KMP 最小循环节
KMP算法: 一:next数组:next[i]就是前面长度为i的字符串前缀和后缀相等的最大长度,也即索引为i的字符失配时的前缀函数. 二:KMP模板 /* pku3461(Oulipo), hdu17 ...
- hdu3746(kmp最小循环节)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746 题意:问在一个字符串末尾加上多少个字符能使得这的字符串首尾相连后能够循环 题解:就是利用next ...
- poj1961 Period kmp解决找字符串的最小循环节
/** 题目:poj1961 Period 链接:http://poj.org/problem?id=1961 题意:求从1到i这个前缀(2<=i<=N) ,如果有循环节(不能自身单独一个 ...
- HDU1358 Period —— KMP 最小循环节
题目链接:https://vjudge.net/problem/HDU-1358 Period Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- UVA 10298 Power Strings 字符串的幂(KMP,最小循环节)
题意: 定义a为一个字符串,a*a表示两个字符相连,即 an+1=a*an ,也就是出现循环了.给定一个字符串,若将其表示成an,问n最大为多少? 思路: 如果完全不循环,顶多就是类似于abc1这样, ...
随机推荐
- 【CF472G】Design Tutorial 压位
题目大意 给出两个\(01\)序列\(A\)和\(B\) 汉明距离定义为两个长度相同的序列中,有多少个对应位置上的数字不一样 \(00111\) 和 \(10101\)的距离为\(2\) \(Q\)次 ...
- nginx配置80端口访问8080+项目名地址
tomcat访问项目,一般是 ip + 端口 + 项目名 nginx 配置 location / {} ,一般只能跳转到 ip + 端口,如果想要直接访问项目,就需要修改tomcat的配置了 如何保证 ...
- windows 路由转发
netsh interface ipv6 install 将内网的2433端口转发到外网的11111端口netsh interface portproxy add v4tov4 listenaddre ...
- Codeforces | CF1033D 【Divisors】
题目大意:给定\(n(1\leq n\leq500)\)个数\(a_1,a_2\cdots,a_n(1\leq a_i\leq2\cdot10^{18})\),每个数有\(3\sim5\)个因数,求\ ...
- 20165223 《JAVA程序设计》第四周学习总结
20165223 <JAVA程序设计>第四周学习总结 教材学习内容总结 第五章要点 子类与继承 成员变量的隐藏和方法重写 super关键字 继承与多态 abstract类与abstract ...
- Golang Kernel For Jupyter-NoteBook
上篇回顾:VSCode and NoteBook for JavaScript 正常流程 安装Go语言:sudo apt install golang 安装内核的相关依赖包:sudo apt inst ...
- 牛客练习赛31 D神器大师泰兹瑞与威穆
双链表搞完了 #include<bits/stdc++.h> using namespace std; #define maxn 1000005 int tot,bac[maxn],fa[ ...
- Linux下无法运行Color picker
➜ ~ com.github.ronnydo.colorpicker com.github.ronnydo.colorpicker: error while loading shared librar ...
- poj2689 Prime Distance
题意:求[a, b]之间差最大/小的相邻素数. 0 < a, b < 2^32, 0 < b - a <= 1e6 首先发现a,b很大,以至于无法求出素数来. 然后就考虑退而求 ...
- Docker下安装Influxdb-1.6.1和Grafana5.2.2
第一步.安装Influxdb 首先启动docker systemctl start docker 然后安装Influxdb(这里解释一下为啥用docker,因为官网下载的话需要FQ[fan-qiang ...