poj3294

时间:2023-01-14 09:40:45

首先后缀数组预处理
然后二分答案len很显然,然后考虑怎么判定
我们用左右指针顺着名次扫描一下,初始左右指针为1
根据LCP(i,j)=min(height[rank[i]+1]~height[rank[j]]) 设rank[i]<rank[j]
移动右指针扫描得到一组后缀[i,j]之间LCP>=len,h[j+1]<len
然后判断一下这组后缀是否有超过半数的原串,如果满足则记录
然后左右指针都从j+1开始
由于每个后缀最多被扫描一次判断一次,所以必然O(n)
注意多个串相连接的时候要用不同的字符作为分隔符

 var ans,x,y,sa,sum,rank,h,loc:array[..] of longint;
v:array[..] of boolean;
j,len,l,r,k,i,n,m,p,tot:longint;
s,ch:ansistring; procedure suffix;
begin
fillchar(sum,sizeof(sum),);
for i:= to n do
begin
y[i]:=ord(s[i]);
inc(sum[y[i]]);
end;
m:=;
for i:= to m do
sum[i]:=sum[i-]+sum[i];
for i:=n downto do
begin
sa[sum[y[i]]]:=i;
dec(sum[y[i]]);
end;
p:=;
rank[sa[]]:=;
for i:= to n do
begin
if (y[sa[i]]<>y[sa[i-]]) then inc(p);
rank[sa[i]]:=p;
end;
m:=p;
j:=;
while m<n do
begin
fillchar(sum,sizeof(sum),);
y:=rank;
p:=;
for i:=n-j+ to n do
begin
inc(p);
x[p]:=i;
end;
for i:= to n do
if sa[i]>j then
begin
inc(p);
x[p]:=sa[i]-j;
end; for i:= to n do
begin
rank[i]:=y[x[i]];
inc(sum[rank[i]]);
end;
for i:= to m do
inc(sum[i],sum[i-]);
for i:=n downto do
begin
sa[sum[rank[i]]]:=x[i];
dec(sum[rank[i]]);
end;
p:=;
rank[sa[]]:=;
for i:= to n do
begin
if (y[sa[i]]<>y[sa[i-]]) or (y[sa[i]+j]<>y[sa[i-]+j]) then inc(p);
rank[sa[i]]:=p;
end;
m:=p;
j:=j shl ;
end;
h[]:=;
p:=;
for i:= to n do
begin
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;
if p> then dec(p);
end;
end; function solve(l,r:longint):boolean;
var i,t:longint;
begin
fillchar(v,sizeof(v),false);
t:=;
for i:=l to r do
if (loc[sa[i]]<>-) then
if not v[loc[sa[i]]] then
begin
inc(t);
v[loc[sa[i]]]:=true;
end;
if t>k shr then exit(true) else exit(false);
end; function check(len:longint):boolean;
var b,e,i:longint;
fl:boolean; begin
fl:=false;
b:=;
e:=;
for i:= to n do
begin
if h[i]>=len then inc(e)
else begin
if solve(b,e) then
begin
if not fl then tot:=;
fl:=true;
inc(tot);
ans[tot]:=sa[b];
end;
b:=i;
e:=i;
end;
end;
if b<e then //注意收尾
begin
if solve(b,e) then
begin
if not fl then tot:=;
inc(tot);
fl:=true;
ans[tot]:=sa[b];
end;
end;
exit(fl);
end; begin
readln(k);
while k<> do
begin
s:='';
r:=;
m:=;
for i:= to k do
begin
readln(ch);
if r<length(ch) then r:=length(ch);
for j:= to length(ch) do
begin
inc(m);
loc[m]:=i;
end;
inc(m);
loc[m]:=-;
s:=s+ch+chr(i);
end;
n:=length(s);
suffix;
l:=;
len:=;
while l<=r do
begin
m:=(l+r) shr ;
if check(m) then
begin
len:=m;
l:=m+;
end
else r:=m-;
end;
if k= then
begin
writeln(s);
writeln;
end
else if len= then
begin
writeln('?');
writeln;
end
else begin
for i:= to tot do
begin;
for j:=ans[i] to ans[i]+len- do
write(s[j]);
writeln;
end;
writeln;
end;
readln(k);
end;
end.

poj3294的更多相关文章

  1. 【POJ3294】 Life Forms (后缀数组&plus;二分)

    Life Forms Description You may have wondered why most extraterrestrial life forms resemble humans, d ...

  2. 【poj3294】 Life Forms

    http://poj.org/problem?id=3294 (题目链接) 题意 给定 n 个字符串,求出现在不小于 k 个字符串中的最长子串. Solution 后缀数组论文题.. 将 n 个字符串 ...

  3. POJ3294 Life Forms —— 后缀数组 最长公共子串

    题目链接:https://vjudge.net/problem/POJ-3294 Life Forms Time Limit: 5000MS   Memory Limit: 65536K Total ...

  4. 【POJ3294】Life Forms(后缀数组,二分)

    题意: n<=100 len[i]<=1000 思路:这是一道论文题 ..]of longint; ch:..]of ansistring; n,n1,l,r,mid,last,i,j,m ...

  5. poj3294 出现次数大于n&sol;2 的公共子串

    Life Forms Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 13063   Accepted: 3670 Descr ...

  6. POJ3294 Life Forms&lpar;后缀数组&rpar;

    引用罗穗骞论文中的话: 将n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组.然后二分答案,用和例3 同样的方法将后缀分成若干组,判断每组的后缀是否出现在不小于k 个的原串中 ...

  7. poj3294 Life Forms(后缀数组)

    [题目链接] http://poj.org/problem?id=3294 [题意] 多个字符串求出现超过R次的最长公共子串. [思路] 二分+划分height,判定一个组中是否包含不小于R个不同字符 ...

  8. poj3294 --Life Forms

    Life Forms Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 12483   Accepted: 3501 Descr ...

  9. Life Forms (poj3294 后缀数组求 不小于k个字符串中的最长子串)

    (累了,这题做了很久!) Life Forms Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 8683   Accepted ...

随机推荐

  1. 纯CSS3实现动态导航栏目

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. &num;英文&num;品读中国城市个性——上海人的精明&amp&semi;头啖汤

    制定"严格的规则" set the 'hard and fast' rules 担负职责 shoulder responsibility 对...有深刻理解 develop a g ...

  3. Word或者Excel中怎么把 &quot&semi;空格&quot&semi; 替换成 &quot&semi;换行 &quot&semi;

    word中ctrl+h打开替换,将" "替换为^pexcel替换成alt+小键盘区的10

  4. 《C&plus;&plus;游戏开发》笔记十二 战争迷雾:初步实现

    本系列文章由七十一雾央编写,转载请注明出处.  http://blog.csdn.net/u011371356/article/details/9475979 作者:七十一雾央 新浪微博:http:/ ...

  5. card布局解决复杂操作的布局问题

    一直不是很待见直接使用card布局,直到对于一些稍微复杂点的业务, 通过border布局和弹窗体的方式解决特别费劲之后,才想起了card布局, 发现card布局真是一个很好的解决办法. 那个使用起来很 ...

  6. Confluence 6 连接到 Jira 用户管理的限制

    当你在使用 JIRA 目录为用户目录的时候,请考虑下面的一些限制和建议. 不知道跨平台的多应用单点登录 当你使用 JIRA 为你的目录管理器的时候,系统将不能支持跨平台的单点登录.当 JIRA 用作目 ...

  7. 从研发到市场,一个C&num;程序员半年神奇之旅

    序 距离上次在博客园发布文章已经过了大约有一年了,由于最近一系列神奇的际遇,让我非常强烈意愿的提起笔来给大家描述我最近一段时间的经历,希望大家根据我的经历做一些参考,我尽量写的逻辑通顺,如果各位兄弟阅 ...

  8. JS发送跨域Post请求出现两次请求的解决办法

    原文地址: http://www.cnblogs.com/JimmyBright/p/7681097.html 所有跨域的js在提交post请求的时候,如果服务端设置了可跨域访问 public sta ...

  9. 二手回收能否翻过BAT这座大山?

    自2015年几大合并事件后,互联网*基本都归于BAT三家.即便近日战火熊熊的本地生活和外卖也都是百度.阿里和腾讯的家门事.创业浪潮在2015年疯狂过后,留给下一年的风口似乎不多了. 不过有媒体预测智 ...

  10. redis的五种常见数据类型的常用指令

      一.String字符串,key-value 应用场景:string是redis的最基本数据类型,key-value格式,一个key对应一个值的情况下 1.设置key = value:set key ...

相关文章