【BZOJ1717】[Usaco2006 Dec]Milk Patterns 产奶的模式 (二分+SA)
求重复k次的最长重复子串,解法见罗穗骞大神的后缀数组论文
- const maxn=;
- var
- x,y,rank,sa,h,s,num,c:array[..maxn] of longint;
- n,time:longint;
- function max(x,y:longint):longint; begin if x>y then exit(x) else exit(y); end;
- function min(x,y:longint):longint; begin if x<y then exit(x) else exit(y); end;
- procedure make;
- var i,j,p,tot:longint;
- begin
- p:=;
- while p<n do
- begin
- fillchar(c,sizeof(c),);
- for i:= to n-p do y[i]:=rank[i+p];
- for i:= n-p+ to n do y[i]:=;
- for i:= to n do inc(c[y[i]]);
- for i:= to n do inc(c[i],c[i-]);
- for i:= to n do
- begin
- sa[c[y[i]]]:=i;
- dec(c[y[i]]);
- end;
- fillchar(c,sizeof(c),);
- for i:= to n do x[i]:=rank[i];
- for i:= to n do inc(c[x[i]]);
- for i:= to n do inc(c[i],c[i-]);
- for i:= n downto do
- begin
- y[sa[i]]:=c[x[sa[i]]];
- dec(c[x[sa[i]]]);
- end;
- for i:= to n do sa[y[i]]:=i;
- tot:=;
- rank[sa[]]:=;
- for i:= to n do
- begin
- if (x[sa[i]]<>x[sa[i-]]) or (x[sa[i]+p]<>x[sa[i-]+p]) then inc(tot);
- rank[sa[i]]:=tot;
- end;
- p:=p<<;
- end;
- end;
- procedure makeht;
- var i,j,p:longint;
- begin
- h[]:=; p:=;
- for i:= to n do
- begin
- p:=max(p-,);
- if rank[i]= then continue;
- j:=sa[rank[i]-];
- while (i+p<=n) and (j+p<=n) and (s[i+p]=s[j+p]) do inc(p);
- h[rank[i]]:=p;
- end;
- end;
- procedure init;
- var i,j,tot:longint;
- ch:char;
- begin
- readln(n,time);
- for i:= to n do readln(s[i]);
- for i:= to n do x[i]:=s[i];
- fillchar(c,sizeof(c),);
- for i:= to n do inc(c[x[i]]);
- for i:= to do inc(c[i],c[i-]);
- for i:= to n do
- begin
- sa[c[x[i]]]:=i;
- dec(c[x[i]]);
- end;
- rank[sa[]]:=;
- tot:=;
- for i:= to n do
- begin
- if x[sa[i]]<>x[sa[i-]] then inc(tot);
- rank[sa[i]]:=tot;
- end;
- make;
- makeht;
- end;
- function check(k:longint):boolean;
- var i,j,x,y:longint;
- begin
- i:=;
- while i<=n do
- begin
- j:=i;
- while (j<n) and (h[j+]>=k) do inc(j);
- if j-i+>=time then exit(true);
- i:=j+;
- end;
- exit(false);
- end;
- procedure solve;
- var l,r,mid,ans:longint;
- begin
- l:=; r:=n>>; ans:=;
- while l<=r do
- begin
- mid:=(l+r)>>;
- if check(mid) then
- begin
- l:=mid+;
- ans:=mid;
- end
- else r:=mid-;
- end;
- writeln(ans);
- end;
- Begin
- init;
- solve;
- End.
【BZOJ1717】[Usaco2006 Dec]Milk Patterns 产奶的模式 (二分+SA)的更多相关文章
- bzoj1717: [Usaco2006 Dec]Milk Patterns 产奶的模式
后缀数组+二分答案+离散化.(上次写的时候看数据小没离散化然后一直WA...写了lsj师兄的写法. #include<cstdio> #include<cstring> #in ...
- BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式( 二分答案 + 后缀数组 )
二分答案m, 后缀数组求出height数组后分组来判断. ------------------------------------------------------------ #include&l ...
- [bzoj1717][Usaco2006 Dec]Milk Patterns 产奶的模式_后缀数组_二分答案
Milk Patterns 产奶的模式 bzoj-1717 Usaco-2006 Dec 题目大意:给定一个字符串,求最长的至少出现了$k$次的子串长度. 注释:$1\le n\le 2\cdot 1 ...
- bzoj1717: [Usaco2006 Dec]Milk Patterns 产奶的模式(后缀数组+二分)
/* 求可重叠的至少重复K次的最长字串 以1为下标起点,因为a[i]最大到1000000,所以要先离散一下 二分长度len 然后O(n)检验 后看h[i]是否有连续的一段h[i]大于len的,并且h[ ...
- [bzoj1717][Usaco2006 Dec]Milk Patterns 产奶的模式 (hash构造后缀数组,二分答案)
以后似乎终于不用去学后缀数组的倍增搞法||DC3等blablaSXBK的方法了= = 定义(来自关于后缀数组的那篇国家集训队论文..) 后缀数组:后缀数组SA是一个一维数组,它保存1..n的某个排列S ...
- [bzoj1717][Usaco2006 Dec]Milk Patterns 产奶的模式——后缀数组
Brief Description 给定一个字符串,求至少出现k次的最长重复子串. Algorithm Design 先二分答案,然后将后缀分成若干组.判断有没有一个组的后缀个数不小于k.如果有,那么 ...
- BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 [后缀数组]
1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1017 Solved: ...
- BZOJ#1717:[Usaco2006 Dec]Milk Patterns 产奶的模式(后缀数组+单调队列)
1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天产奶的 ...
- BZOJ_1717_[Usaco2006 Dec]Milk Patterns 产奶的模式_后缀数组
BZOJ_1717_[Usaco2006 Dec]Milk Patterns 产奶的模式_后缀数组 Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他 ...
随机推荐
- 【CF739E】Gosha is hunting(WQS二分套WQS二分)
点此看题面 大致题意: 你有两种捕捉球(分别为\(A\)个和\(B\)个),要捕捉\(n\)个神奇宝贝,第\(i\)个神奇宝贝被第一种球捕捉的概率是\(s1_i\),被第二种球捕捉的概率是\(s2_i ...
- MySQL8.0在Windows下的安装和使用
前言 MySQL在Windows下有2种安装方式:1.图形化界面方式安装MySQL 2.noinstall方式安装MySQL.在这里,本文只介绍第二种方式:以noinstall方式安装MySQL,以及 ...
- Finite Encyclopedia of Integer Sequences(找规律)
6617: Finite Encyclopedia of Integer Sequences 时间限制: 1 Sec 内存限制: 128 MB提交: 375 解决: 91[提交] [状态] [讨论 ...
- angular6项目中使用echarts图表的方法(有一个坑,引用报错)
1.安装相关依赖(采用的webpack) npm install ecahrts --save npm install ngx-echarts --save 2.angular.json 配置echa ...
- java常用 开源
http://sourceforge.nethttp://code.google.com/hosting/http://www.open-open.com/code/tags/Javahttp://w ...
- c++ 作业 10月13日 进制转换最简单方法,控制c++输出格式方法 教材50的表格自己实践一下 例题3.1 setfill() setw()
#include <iostream> #include <iomanip> using namespace std; int main(){ // int i; // cou ...
- response.setContentType("text/html;charset=utf-8")后依然乱码的解决方法
从浏览器获取数据到服务器,服务器将得到数据再显示在浏览器上英文字母正常显示,中文字符乱码的问题,已经使用了 response.setContentType("text/html;charse ...
- notify()和notifyAll()主要区别
notify()和notifyAll()都是Object对象用于通知处在等待该对象的线程的方法. void notify(): 唤醒一个正在等待该对象的线程.void notifyAll(): 唤醒所 ...
- JavaScript之map与parseInt的陷阱
问题来源 这个问题的来源是学习廖雪峰老师JS教程.问题如下:小明希望利用map()把字符串变成整数,他写的代码很简洁: 'use strict'; var arr = ['1', '2', '3' ...
- 【IDEA】热部署插件Jrebel破解安装
JRebel 介绍 IDEA上原生是不支持热部署的,一般更新了 Java 文件后要手动重启 Tomcat 服务器,才能生效,浪费不少生命啊.目前对于idea热部署最好的解决方案就是安装JRebel插件 ...