【POJ2774&Ural1517】Long Long Message(后缀数组)
题意:求两个字符串的最长公共子串
n<=1000
思路:这是一道论文题


var x,y,sa,rank,wc,wd,a,height:array[..]of longint;
n,l1,l2,i,ans,m,l,r:longint;
ch:ansistring; procedure swap(var x,y:longint);
var t:longint;
begin
t:=x; x:=y; y:=t;
end; function max(x,y:longint):longint;
begin
if x>y then exit(x);
exit(y);
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,j,k: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; begin
assign(input,'poj2774.in'); reset(input);
assign(output,'poj2774.out'); rewrite(output);
readln(ch);
l1:=length(ch);
for i:= to l1- do a[i]:=ord(ch[i+]);
a[l1]:=;
readln(ch);
l2:=length(ch);
for i:=l1+ to l1+l2 do a[i]:=ord(ch[i-l1]);
n:=l1+l2+; a[n]:=; m:=;
getsa(n+);
getheight(n);
inc(n);
for i:= to n do
begin
l:=sa[i-]+; r:=sa[i]+;
if l>r then swap(l,r);
if (l<=l1)and(r>=l1+) then ans:=max(ans,height[i]);
end; writeln(ans); close(input);
close(output);
end.
【POJ2774&Ural1517】Long Long Message(后缀数组)的更多相关文章
- POJ2774 Long Long Message —— 后缀数组 两字符串的最长公共子串
题目链接:https://vjudge.net/problem/POJ-2774 Long Long Message Time Limit: 4000MS Memory Limit: 131072 ...
- poj2774 Long Long Message 后缀数组求最长公共子串
题目链接:http://poj.org/problem?id=2774 这是一道很好的后缀数组的入门题目 题意:给你两个字符串,然后求这两个的字符串的最长连续的公共子串 一般用后缀数组解决的两个字符串 ...
- (HDU 5558) 2015ACM/ICPC亚洲区合肥站---Alice's Classified Message(后缀数组)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5558 Problem Description Alice wants to send a classi ...
- POJ 2774 Long Long Message 后缀数组
Long Long Message Description The little cat is majoring in physics in the capital of Byterland. A ...
- poj 2774 Long Long Message 后缀数组基础题
Time Limit: 4000MS Memory Limit: 131072K Total Submissions: 24756 Accepted: 10130 Case Time Limi ...
- POJ2774Long Long Message (后缀数组&后缀自动机)
问题: The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to ...
- poj 2774 Long Long Message 后缀数组LCP理解
题目链接 题意:给两个长度不超过1e5的字符串,问两个字符串的连续公共子串最大长度为多少? 思路:两个字符串连接之后直接后缀数组+LCP,在height中找出max同时满足一左一右即可: #inclu ...
- POJ-2774-Long Long Message(后缀数组-最长公共子串)
题意: 给定两个字符串 A 和 B,求最长公共子串. 分析: 字符串的任何一个子串都是这个字符串的某个后缀的前缀. 求 A 和 B 的最长公共子串等价于求 A 的后缀和 B 的后缀的最长公共前缀的最大 ...
- POJ 2774 Long Long Message 后缀数组模板题
题意 给定字符串A.B,求其最长公共子串 后缀数组模板题,求出height数组,判断sa[i]与sa[i-1]是否分属字符串A.B,统计答案即可. #include <cstdio> #i ...
- POJ 2774 Long Long Message (后缀数组+二分)
题目大意:求两个字符串的最长公共子串长度 把两个串接在一起,中间放一个#,然后求出height 接下来还是老套路,二分出一个答案ans,然后去验证,如果有连续几个位置的h[i]>=ans,且存在 ...
随机推荐
- [BZOJ2761][JLOI2011]不重复数字 暴力
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2761 直接暴力. #include<cstdio> #include<c ...
- Arduino Ethernet W5100扩展板的指示灯含义
Arduino Ethernet W5100扩展板是继承WIZnet W5100网络芯片的扩展板.将扩展板连接到Arduino后,可使Arduino具有网络功能.此扩展板上有多个指示灯,由于轻易查不到 ...
- UML建模图实战笔记
一.前言 UML:Unified Modeling Language(统一建模语言),使用UML进行建模的作用有哪些: 可以更好的理解问题 可以及早的发现错误或者被遗漏的点 可以更加方便的进行组员之间 ...
- 解决./mysql-bin.index’ not found (Errcode: 13)
问题出现在升级php版本以后,网站无法连接数据库,phpMyAdmin无法登录: 然后尝试开启mysql,/etc/init.d/mysqld start ,提示: Starting MySQL. E ...
- LR 两种录制:html与url
一直在使用LR,对于Html_based script和Url-based script 两种录制方式之间,要如何选择,仍是一知半解.最近测试时遇到同样的业务功能,两种录制方式的脚本,单次执行时间差别 ...
- js生成随机的uuid
function generateUUID() { var d = new Date().getTime(); if(window.performance && typeof wind ...
- 目标检测中bounding box regression
https://zhuanlan.zhihu.com/p/26938549 RCNN实际包含两个子步骤,一是对上一步的输出向量进行分类(需要根据特征训练分类器):二是通过边界回归(bounding-b ...
- python爬虫---从零开始(三)Requests库
1,什么是Requests库 Requests是用python语言编写,基于urllib,采用Apache2 Licensed 开源协议的HTTP库. 它比urllib更加方便,可以节约我们大量的工作 ...
- Report Builder 打开报错
提示:REP-0756:警告:找不到PL/SQL程序库’inv.pll’. 解决办法 处理:1.运行 ---输入REgedit ,在注册表内,查找注册表项Reports_path. 2.将下载的.pl ...
- 工作流activi链接地址
http://topmanopensource.iteye.com/blog/1313865