SP263 PERIOD - Period KMP技巧】的更多相关文章

[题解]PERIOD - Period [POJ1961] [SP263] 在进入这道题之前,我们需要了解 kmp 算法 不知道的童鞋可以去看一下Silent_EAG(一个可爱的女孩纸)的讲解. 关于 kmp 算法中 next 数组的周期性质 引理: 对于某一字符串 \(S[1\)-\(i ]\),在它众多的\(next[ i ]\)的"候选项"中,如果存在某一个\(next[ i ]\),使得: \(i\) % \(( i - next[ i ] ) == 0\) ,那么 \(S[…
\(\color{#0066ff}{题目描述}\) 如果一个字符串S是由一个字符串T重复K次形成的,则称T是S的循环元.使K最大的字符串T称为S的最小循环元,此时的K称为最大循环次数. 现给一个给定长度为N的字符串S,对S的每一个前缀S[1~i],如果它的最大循环次数大于1,则输出该前缀的最小循环元长度和最大循环次数. \(\color{#0066ff}{输入格式}\) 第一行一个T,T组数据\(T \leq 10\) 每组数据一个n,\(n\leq 1000000\),表示字符串长度 接下来是…
Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4437    Accepted Submission(s): 2145 Problem Description For each prefix of a given string S with N characters (each character has an ASCII…
Problem Description For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SIZE(S)-p-1], then the prefix is a “period” of S. We want to all the periodic prefixs.  Input Input contains multiple cases. The first line contains an…
Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 20436   Accepted: 9961 Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the…
Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2398    Accepted Submission(s): 1187 Problem Description For each prefix of a given string S with N characters (each character has an ASCII…
I - Period Problem Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 <= i <= N) we want…
Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3196    Accepted Submission(s): 1603 Problem Description For each prefix of a given string S with N characters (each character has an ASCII…
Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4325    Accepted Submission(s): 2087 Problem Description For each prefix of a given string S with N characters (each character has an ASCI…
题目链接: Problem 1901 Period II 题目描述: 给出一个串,满足长度为p的前缀和长度为p的后缀相等的p的个数,输出p的个数,和p分别是多少? 解题思路: 对kmp的next数组的理解程度,next[i] = j的时候,就是当子串匹配到i的时候失配,就回溯到j的位置从新匹配,(s[0, j] == s[i-j, i]) 对于next[len] = x, s[0, x] == s[len-x, len]. next[x] = y, s[0, y] == s[x - y, x];…
一个带有 n 个字符的字符串 s ,要求找出 s 的前缀中具有循环结构的字符子串,也就是要输出具有循环结构的前缀的最后一个数下标与其对应最大循环次数.(次数要求至少为2) For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a peri…
Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 11356   Accepted: 5279 Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the…
Period Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 53   Accepted Submission(s) : 27 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description For each prefix of a given str…
题目描述 For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 <= i <= N) we want to know the largest K >…
For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SIZE(S)-p-1], then the prefix is a “period” of S. We want to all the periodic prefixs. Input Input contains multiple cases. The first line contains an integer T representin…
题目链接:https://vjudge.net/problem/FZU-1901  Problem 1901 Period II Accept: 575    Submit: 1495Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SIZE(S)-p-…
For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 <= i <= N) we want to know the largest K > 1 (…
http://poj.org/problem?id=1961 题意 :给你一个字符串,让你输出到第几个字符时,循环结的个数. 思路 :这个题和2409差不多,稍微修改一下,加一个循环就行了,用的也是KMP. #include <string.h> #include <stdio.h> #include <iostream> using namespace std ; ; char ch[maxn] ; int next[maxn] ; int main() { int…
题目链接:http://vjudge.net/problem/viewProblem.action?id=29342 题目大意:给定字符串,找到每个前缀的最大循环节的个数. 首先当然是kmp预处理,接下来的问题是 怎么找循环节? 用反证法可以证明,如果f[i]~i之间的字符串能构成循环节,则该字符串就是i前缀对应的循环节,否则循环节不存在. 对每个前缀找到尾指针对应的失陪位置后,不需要按失陪指针继续往前寻找了(否则超时). 只用判断上个位置到尾部的字符串是否是循环节(长度是否有整除关系),即知循…
思路: 这里只要注意一点,就是失配值和前后缀匹配值的区别,不懂的可以看看这里,这题因为对子串也要判定,所以用前后缀匹配值,其他的按照最小循环节做 代码: #include<iostream> #include<algorithm> const int N = 1000000+5; const int INF = 0x3f3f3f3f; using namespace std; int fail[N]; char p[N]; void getFail(){ fail[0] = -1;…
题意:给定一个长度为n字符串s,求它每个前缀的最短循环节.也就是对于每个i(2<=i<=n),求一个最大整数k>1(如果存在),使得s的前i个字符组成的前缀是某个字符串重复得k次得到的.输出所有的的k和i. 析:首先这是一个KMP的一个题(据大神们说这是一个水题...),首先要对KMP有了解,如果没有了解的先看一下,提供一个地址学习KMP算法, http://www.cnblogs.com/dwtfukgv/articles/5532277.html 对KMP有所了解后,其实这就是一个对…
kmp的代码很短,但是不太容易理解,还是先说明一下这个算法过程吧. 朴素的字符串匹配大家都懂,但是效率不高,原因在哪里? 匹配过程没有充分利用已经匹配好的模版的信息,比如说, i是文本串当前字符的下标,j是要匹配的模版串当前正在匹配的字符的下标.(下标都从零开始,j同时可以表示已经匹配的字符长度) 当匹配到i = 4, j = 4的时候失配了,朴素的匹配做法是往右边移一位然后从j开始扫,这样做效率很低. 不难发现前面已经匹配好的串ab是最长公共前缀后缀.把串移动到后缀的第一个位置正好是 朴素的匹…
题意:统计单串中从某个位置以前有多少重复的串 思路:kmp模板 #include<iostream> #include<stdio.h> #include<string.h> using namespace std; #define MaxSize 1000005 char str[MaxSize]; int next2[MaxSize]; void GetNext(char t[]){ int j,k,len; j=; k=-; next2[]=-; len=strl…
Problem - 1358 KMP求循环节次数.题意是,给出一个长度为n的字符串,要求求出循环节数大于1的所有前缀.可以直接用KMP的方法判断是否有完整的k个循环节,同时计算出当前前缀的循环节的个数. 代码如下: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; ; char buf[N]; int next[…
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1901 题目大意:题目大意求出所有p满足s[i]=s[i+p](i<=len-p) 解题思路: 其实就是要找出所有的循环节(不只是最小的),循环节本质跟公共前后缀有关,可以通过递归的方法求出所有公共前后缀ti,那么len-ti就是相应循环节. 之前写的计算最小循环节,累加循环节得到前缀的方法是有问题的,过不了下面这种数据.数据:abacaba结果应该是4,6,7而求出来的是4,7.因为忽略了除了最小循环节外的…
鲜有的在luogu发题解以及使用LaTex??? 就丢链接跑了.…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 题目大意:给你一个长度为 \(n\) 的字符串 \(s\) ,那么它有 \(n\) 个前缀. 对于第 \(i\) 个前缀 \(t\) ,如果他们表示成一个子串重复 \(K\) 次 \((K>1)\) ,那么我们就输出这个前缀 \(t\) 的长度以及对应的最大的 \(K\) .(因为对于 \(aaaa\) 来说,\(K\) 可以为 \(4\) 或者 \(2\) ,但是 \(4\) 比较大,所以选…
目录 简介 Duration Period ChronoUnit 简介 在JDK8中,引入了三个非常有用的时间相关的API:Duration,Period和ChronoUnit. 他们都是用来对时间进行统计的,本文将会详细讲解一下这三个API的使用. Duration Duration主要用来衡量秒级和纳秒级的时间,使用于时间精度要求比较高的情况. 先来看看Duration的定义: public final class Duration implements TemporalAmount, Co…
Few examples to show you how to use Java 8 Duration, Period and ChronoUnit objects to find out the difference between dates. Duration – Measures time in seconds and nanoseconds. Period – Measures time in years, months and days. 1. Duration Example A …
在使用Java8 新特性中关于Period.between的方法时需注意该方法获取日期的区间问题. @Test public void test1(){ LocalDate from = LocalDate.of(2018,10,1); System.out.println(Period.between(from,LocalDate.now()).getDays()); } 首先,猜测一下上面的代码返回的天数是多少?15天,你猜对了吗? 如果不理解为什么是15天,那么咱们再打印一下其他的心气,你…