题意:求字符串的可重叠的k次最长重复子串

n<=20000 a[i]<=1000000

思路:后缀数组+二分答案x,根据height分组,每组之间的height>=x

因为可以重叠,所以只要判断是否有一组的height个数>=k即可

 var sa,rank,x,y,a,wc,wd,height:array[..]of longint;
n,m,i,l,r,mid,last,k1:longint; procedure swap(var x,y:longint);
var t:longint;
begin
t:=x; x:=y; y:=t;
end; function cmp(a,b,l:longint):boolean;
begin
exit((y[a]=y[b])and(y[a+l]=y[b+l]));
end; procedure getsa(n:longint);
var i,j,p:longint;
begin
for i:= to n- do
begin
x[i]:=a[i];
inc(wc[a[i]]);
end;
for i:= to m- do wc[i]:=wc[i-]+wc[i];
for i:=n- downto do
begin
dec(wc[x[i]]);
sa[wc[x[i]]]:=i;
end;
j:=; p:=;
while p<n do
begin
p:=;
for i:=n-j to n- do
begin
y[p]:=i; inc(p);
end;
for i:= to n- do
if sa[i]>=j then begin y[p]:=sa[i]-j; inc(p); end;
for i:= to n- do wd[i]:=x[y[i]];
for i:= to m- do wc[i]:=;
for i:= to n- do inc(wc[wd[i]]);
for i:= to m- do wc[i]:=wc[i-]+wc[i];
for i:=n- downto do
begin
dec(wc[wd[i]]);
sa[wc[wd[i]]]:=y[i];
end;
for i:= to n do swap(x[i],y[i]);
p:=; x[sa[]]:=;
for i:= to n- do
if cmp(sa[i-],sa[i],j) then x[sa[i]]:=p-
else begin x[sa[i]]:=p; inc(p); end;
j:=j*;
m:=p;
end;
end; procedure getheight(n:longint);
var i,k,j:longint;
begin
for i:= to n do rank[sa[i]]:=i;
k:=;
for i:= to n- do
begin
if k> then dec(k);
j:=sa[rank[i]-];
while a[i+k]=a[j+k] do inc(k);
height[rank[i]]:=k;
end;
end; function isok(x:longint):boolean;
var s,i:longint;
begin
s:=;
for i:= to n do
begin
if height[i]<x then
begin
if s>=k1 then exit(true);
s:=;
end
else inc(s);
end;
if s>=k1 then exit(true);
exit(false);
end; begin while not eof do
begin
fillchar(a,sizeof(a),);
fillchar(sa,sizeof(sa),);
fillchar(rank,sizeof(rank),);
fillchar(x,sizeof(x),);
fillchar(y,sizeof(y),);
fillchar(height,sizeof(height),);
fillchar(wc,sizeof(wc),);
fillchar(wd,sizeof(wd),);
readln(n,k1);
if n= then break;
for i:= to n- do
begin
read(a[i]);
inc(a[i]);
end;
a[n]:=; m:=;
getsa(n+);
getheight(n);
l:=; r:=n; last:=;
while l<=r do
begin
mid:=(l+r)>>;
if isok(mid) then begin last:=mid; l:=mid+; end
else r:=mid-;
end;
writeln(last);
// for i:= to n do writeln(height[i]);
end; end.

【BZOJ1717&POJ3261】Milk Patterns(后缀数组,二分)的更多相关文章

  1. POJ-3261 Milk Patterns,后缀数组+二分。。

                                                        Milk Patterns 题意:求可重叠的至少重复出现k次的最长的字串长. 这题的做法和上一题 ...

  2. Poj 3261 Milk Patterns(后缀数组+二分答案)

    Milk Patterns Case Time Limit: 2000MS Description Farmer John has noticed that the quality of milk g ...

  3. POJ3261 Milk Patterns —— 后缀数组 出现k次且可重叠的最长子串

    题目链接:https://vjudge.net/problem/POJ-3261 Milk Patterns Time Limit: 5000MS   Memory Limit: 65536K Tot ...

  4. BZOJ 1717 [USACO06DEC] Milk Patterns (后缀数组+二分)

    题目大意:求可重叠的相同子串数量至少是K的子串最长长度 洛谷传送门 依然是后缀数组+二分,先用后缀数组处理出height 每次二分出一个长度x,然后去验证,在排序的后缀串集合里,有没有连续数量多于K个 ...

  5. poj3261 Milk Patterns 后缀数组求可重叠的k次最长重复子串

    题目链接:http://poj.org/problem?id=3261 思路: 后缀数组的很好的一道入门题目 先利用模板求出sa数组和height数组 然后二分答案(即对于可能出现的重复长度进行二分) ...

  6. poj 3261 Milk Patterns 后缀数组 + 二分

    题目链接 题目描述 给定一个字符串,求至少出现 \(k\) 次的最长重复子串,这 \(k\) 个子串可以重叠. 思路 二分 子串长度,据其将 \(h\) 数组 分组,判断是否存在一组其大小 \(\ge ...

  7. [USACO06FEC]Milk Patterns --- 后缀数组

    [USACO06FEC]Milk Patterns 题目描述: Farmer John has noticed that the quality of milk given by his cows v ...

  8. POJ3261 Milks patterns(后缀数组)

    Farmer John has noticed that the quality of milk given by his cows varies from day to day. On furthe ...

  9. 【poj 3261】Milk Patterns 后缀数组

    Milk Patterns 题意 给出n个数字,以及一个k,求至少出现k次的最长子序列的长度 思路 和poj 1743思路差不多,二分长度,把后缀分成若干组,每组任意后缀公共前缀都>=当前二分的 ...

  10. POJ 3261 Milk Patterns 后缀数组求 一个串种 最长可重复子串重复至少k次

    Milk Patterns   Description Farmer John has noticed that the quality of milk given by his cows varie ...

随机推荐

  1. fetch和axios区别,proxy代理配置

    1.今天使用fetch调用接口时使用console.log(res.data)始终是undefined,使用anxios请求则可以成功请求到数据,非常奇怪,于是查了一圈,才搞明白是我自以为了,哎,浪费 ...

  2. 新建cordova应用,插件开发教程系列(总目录)

    以下几篇是连续的教程,代码也是连续的,包括如下章节: 新建cordova应用 https://www.cnblogs.com/cannel/p/11074359.html 使用cordova把h5应用 ...

  3. Android获取本地相册图片、拍照获取图片

    需求:从本地相册找图片,或通过调用系统相机拍照得到图片. 容易出错的地方: 1,当我们指定了照片的uri路径,我们就不能通过data.getData();来获取uri,而应该直接拿到uri(用全局变量 ...

  4. Clean Code 第十章 : 类

    最近的CleanCode读到了第十章.这一张主要讲了如何去构造一个类,感觉的CleanCode至此已经不仅仅是单纯的讲如何'写'出漂亮的代码,而是从设计方向上去构造出好的代码了. 本章节主要讲了: * ...

  5. Spring中@Value的使用

  6. 生成hprof文件,用MAT进行分析

    生成hprof文件可以在DDMS选中进程点击窗口左上角的"dump hprof file"按钮来直接生成,也可以通过在程序加代码中来生成 代码2: void generateHpr ...

  7. UVA 11922 Permutation Transformer (Splay树)

    题意: 给一个序列,是从1~n共n个的自然数,接下来又m个区间,对于每个区间[a,b],从第a个到第b个从序列中分离出来,翻转后接到尾部.输出最后的序列. 思路: 这次添加了Split和Merge两个 ...

  8. 洛谷 P1955 程序自动分析

    题目描述 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3...代表程序中出现的变量,给定n个形如xi=xj或xi≠xj的变 ...

  9. SQLite-Like语句

    SQLite – LIKE子句 使用SQLite LIKE运算符 用于匹配文本.如果搜索表达式可以匹配模式表达式,如操作符将返回true,这是1.有两个通配符与Like操作符一起使用: The per ...

  10. 【Hive】explain command throw ClassCastException in 2.3.4

    参考:https://issues.apache.org/jira/browse/HIVE-21489 (一)问题描述: Hive-2.3.4 执行  explain select * from sr ...