[LA3026]Period
[LA3026]Period
试题描述
输入
输出
输入示例
3 aaa 12 aabaabaabaab 0
输出示例
Test case #1 2 2 3 3Test case #2 2 2 6 2 9 3 12 4
数据规模及约定
见“输入”
题解
KMP 裸题,对于位置 i,它指向的失配的位置为 f[i+1],那么当 f[i+1] > 1 且 (i - f[i+1] + 1) | i 时答案为 i / (i - f[i+1] + 1). 我 KMP 从 1 开始做的所以前面的式子可能会奇怪一些。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std;int read() {int x = 0, f = 1; char c = getchar();while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }return x * f;
}#define maxn 1000010
int n, f[maxn];
char S[maxn];int main() {n = read();int kase = 0; // bool fl = 1;while(n) {scanf("%s", S + 1);
// if(!fl) putchar('\n'); fl = 0;printf("Test case #%d\n", ++kase);f[1] = f[2] = 1;for(int i = 2; i <= n; i++) {int u = f[i];while(u > 1 && S[u] != S[i]) u = f[u];f[i+1] = S[u] == S[i] ? u + 1 : u;if(f[i+1] > 1 && i % (i + 1 - f[i+1]) == 0) printf("%d %d\n", i, i / (i + 1 - f[i+1]));}putchar('\n');n = read();}return 0;
}
转载于:https://www.cnblogs.com/xiao-ju-ruo-xjr/p/5753884.html
[LA3026]Period相关推荐
- LA3026 Period
题意大概是,给你一个字符串,如果该字符串的某一个前缀Si是由若干个相同的字符串循环构成,就输出i和最短循环节长度 利用KMP算法里面失配函数可以解决这个问题,失配函数f(i)可以定义为字符串的前缀Si ...
- 时间周期 java_周期和持续时间 / Period and Duration
# 周期和持续时间 / Period and Duration 当您编写代码来指定一段时间时,请使用最符合您需要的类或方法: Duration 类, Period 类或 ChronoUnit.betw ...
- java between_Java8 Period.between方法坑及注意事项
在使用Java8 新特性中关于Period.between的方法时需注意该方法获取日期的区间问题. @Test public void test1(){ LocalDate from = LocalD ...
- HDU 5908 Abelian Period 暴力
Abelian Period 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5908 Description Let S be a number st ...
- Java 8 – Period and Duration examples
Few examples to show you how to use Java 8 Duration, Period and ChronoUnit objects to find out the d ...
- Back Stub Period
http://www.investopedia.com/terms/p/portfolio.asp#axzz1lnDvrq00 The last interim period in the life ...
- JDK8中的新时间API:Duration Period和ChronoUnit介绍
文章目录 简介 Duration Period ChronoUnit 简介 在JDK8中,引入了三个非常有用的时间相关的API:Duration,Period和ChronoUnit. 他们都是用来对时 ...
- Java8中使用以下类计算日期时间差:Period、Duration、ChronoUnit
一.简述 在Java8中,我们可以使用以下类来计算日期时间差异: 1.Period 2.Duration 3.ChronoUnit 二.Period类 主要是Period类方法getYears(),g ...
- 【POJ - 1961】Period(KMP,循环节问题)
题干: For each prefix of a given string S with N characters (each character has an ASCII code between ...
最新文章
- 设置Open in Terminal快捷键Alt+Shift+Z,方便angular项目的各种命令输入(多任务状态下)
- AI算法起家的今日头条为何败给了色情?一文告诉你机器学习何以搞不定鉴黄
- MILA研究院唐建:基于图神经网络的关系推理(附视频)
- 在ubuntu上安装,使用MQTT Mosquitto
- 容器处于restarting状态_Docker容器操作-基础命令
- mysql pgsql 2017,DB-Engines 2017 年度数据库:PostgreSQL 实至名归
- Dalvik线程模型
- 我在 1969 年写代码
- 部分Excel函数的使用
- 11.sql条件查询
- 【Mybatis学习路线】day02mybatis的增删改查操作
- redis查看集合中元素的数量,scard
- [Git 1]基本操作与协同开发
- SpringCloud-Seata分布式事务服务案例之订单Order服务搭建(Day16)
- matlab做的脑网络分析,eeg脑网络分析
- 疲劳驾驶检测系统的研究
- 2023年全国最新会计专业技术资格精选真题及答案16
- 2020年车联网行业深度报告 附下载地址
- GOA WinForms 系列
- (K8s入门到精通) 10 k8s service(SVC),管理多个pod信息
热门文章
- Excel公式与函数案例速查手册/电脑技巧从入门到精通丛书
- 今天下午接到阔总编的电话
- ImportError cannot import name BytesIO when import caffe
- 【数据平台】sqoop支持hive和mysql互导的基本语句格式
- vue中引入jquery
- Vue常用特性——表单操作、表单域修饰符(number:转化为数值 ;trim:去掉开始和结尾的空格 ; lazy : 将input事件切换为change事件)||自定义指令|| 局部指令
- 多重循环 ——— 打印九九乘法表 || 经典的打印金字塔(打印整个金字塔 打印空心金字塔 打印空心菱形金字塔)
- 标签页使用及bug解决
- Windows 技术篇-LDSGameMaster文件夹有什么用,删除方法
- C# ListView控件显示表格(自适应宽度),添加 Checkbox,删除选择项,选中颜色和鼠标滑过背景变色