传送门 后缀数组经典题. 貌似可以用二分答案+后缀数组? 我自己yyyyyy了一个好写一点的方法. 直接先预处理出heightheightheight数组. 然后对于所有连续的k−1k-1k−1个heightheightheight的最小值取最大值即可. 代码: #include<iostream> #include<cstdio> #include<algorithm> #define ri register int using namespace std; inli…
传送门 后缀排序模板题. 终于会后缀数组了(然而只会倍增并不会DC3DC3DC3). 在这里列举几个数组的意思: sai:sa_i:sai​:当前排名第iii的后缀的起始下标. rkirk_irki​当前下标为iii的后缀对应的排名. sa2isa2_isa2i​当前排名为iii的第二关键字对应的下标. 代码: #include<bits/stdc++.h> #define ri register int using namespace std; const int N=1e6+5; int…
题目地址:http://poj.org/problem?id=3261 题目: Description Farmer John has noticed that the quality of milk given by his cows varies from day to day. On further investigation, he discovered that although he can't predict the quality of milk from one day to…
题意: 给定一个字符串,求至少出现k 次的最长重复子串,这k 个子串可以重叠. 分析: 先二分答案,然后将后缀分成若干组. 不同的是,这里要判断的是有没有一个组的后缀个数不小于k. 如果有,那么存在k 个相同的子串满足条件,否则不存在.这个做法的时间复杂度为O(nlogn). // File Name: 3261.cpp // Author: Zlbing // Created Time: 2013年09月04日 星期三 21时21分51秒 #include<iostream> #includ…
传送门 后缀数组好题. 考虑枚举循环节长度lenlenlen. 然后考虑枚举循环节的起点来更新答案. 但是直接枚举每次O(n)O(n)O(n). 考虑枚举len∗k+1len*k+1len∗k+1作为起点. 然后用len∗(k−1)+1len*(k-1)+1len∗(k−1)+1和len∗k+1len*k+1len∗k+1之间的某一段有可能使循环节长度再加一. 代码: #include<iostream> #include<cstdio> #include<cstring&g…
传送门 实际上可以用后缀自动机秒掉 当然后缀数组也挺好写. 我们将两个字符串接在一起,为了方便中间用一个特殊字符连接. 然后对新字符串求heightheightheight数组. 求出来之后对所有满足sai,sai−1sa_i,sa_{i-1}sai​,sai−1​属于两个不同字符串的heightheightheight取最大值就行了. 代码: #include<iostream> #include<cstdio> #include<cstring> #define r…
[USACO06FEC]Milk Patterns 题目描述: Farmer John has noticed that the quality of milk given by his cows varies from day to day. On further investigation, he discovered that although he can't predict the quality of milk from one day to the next, there are…
Farmer John has noticed that the quality of milk given by his cows varies from day to day. On further investigation, he discovered that although he can't predict the quality of milk from one day to the next, there are some regular patterns in the dai…
Milk Patterns Case Time Limit: 2000MS Description Farmer John has noticed that the quality of milk given by his cows varies from day to day. On further investigation, he discovered that although he can't predict the quality of milk from one day to th…
题目链接:http://poj.org/problem?id=3261 思路: 后缀数组的很好的一道入门题目 先利用模板求出sa数组和height数组 然后二分答案(即对于可能出现的重复长度进行二分) ,二分的时候,对 height进行分组,看是否存在一组height值使得其重复的次数大于等于k 代码如下: #include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> usin…