...又是TLE,对于单组数据肯定TLE不了,问题是多组的时候就呵呵了...

按height分组去搞,然后判一下是否不属于同一个串...

const maxn=;
var
x,y,rank,sa,c,col,h,rec:array[..maxn] of longint;
pd:array[..maxn] of boolean;
s:ansistring;
n,k,maxlen,cnta: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 swap(var x,y:longint);var tmp:longint; begin tmp:=x;x:=y;y:=tmp; end; procedure make;
var i,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;
for i:= to n do sa[rank[i]]:=i;
end; procedure makeh;
var i,p,j:longint;
begin
p:=; h[]:=;
for i:= to n do
begin
p:=max(p-,);
if rank[i]= then continue;
j:=sa[rank[i]-];
while (j+p<=n) and (i+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;
s1:ansistring;
begin
k:=n>>;
readln(s);
tot:=;
maxlen:=length(s);
for i:= to maxlen do col[i]:=;
for i:= to n do
begin
readln(s1);
s:=s+'#';
maxlen:=max(length(s1),maxlen);
inc(tot);
for j:= length(s)+ to length(s)+length(s1) do col[j]:=tot;
s:=s+s1;
end;
n:=length(s);
fillchar(c,sizeof(c),);
for i:= to n do x[i]:=ord(s[i]);
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;
tot:=;
rank[sa[]]:=;
for i:= to n do
begin
if x[sa[i]]<>x[sa[i-]] then inc(tot);
rank[sa[i]]:=tot;
end;
make; makeh;
end; function check(x:longint):boolean;
var i,j,tot,cnt:longint;
begin
fillchar(pd,sizeof(pd),false);
pd[]:=true; tot:=; cnt:=;
if not pd[sa[]] then inc(tot);
pd[sa[]]:=true;
for i:= to n do
begin
if h[i]<x then
begin
if tot>k then
begin
inc(cnt);
rec[cnt]:=i-;
end;
tot:=;
fillchar(pd,sizeof(pd),false);
pd[]:=true;
end;
if not pd[col[sa[i]]] then inc(tot);
pd[col[sa[i]]]:=true;
end;
if tot>k then
begin
inc(cnt);
rec[cnt]:=i-;
end;
if cnt> then
begin
cnta:=cnt;
exit(true);
end;
exit(false);
end; procedure qsort(l,r:longint);
var i,j,mid,tmp:longint;
begin
if l>r then exit;
i:=l; j:=r;
mid:=rec[l+random(r-l+)];
repeat
while rec[i]<mid do inc(i);
while rec[j]>mid do dec(j);
if i<=j then
begin
swap(i,j);
inc(i); dec(j);
end;
until i>j;
qsort(i,r); qsort(l,j);
end; procedure solve;
var l,r,mid,tot,ans,i,j:longint;
begin
l:=; r:=maxlen; ans:=;
while l<=r do
begin
mid:=(l+r)>>;
if check(mid) then
begin
ans:=mid;
l:=mid+;
end
else r:=mid-;
end;
fillchar(pd,sizeof(pd),false);
if ans= then
begin
writeln('?');
exit;
end;
qsort(,cnta);
for i:= to cnta do writeln(copy(s,sa[rec[i]],ans));
end; Begin
readln(n);
while n<> do
begin
init;
solve;
writeln;
readln(n);
end;
End.

【POJ3294】 Life Forms(SA)的更多相关文章

  1. 【POJ3294】 Life Forms (后缀数组+二分)

    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(后缀数组,二分)

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

  4. 【转】Xamarin Forms 介绍

    特此声明,本篇博文转自:http://blog.csdn.net/kinfey/article/details/29621381 什么是 Xamarin Forms ? Xamarin Forms 是 ...

  5. 【转】SQL2008的sa账户被禁用,其他账户无法连接的解决方法

    或者你还有其它的sysadmin权限的账号,你可以用此账号登录,重置SA密码. 但是在以下情况下,怎么办呢? 1. SA密码丢失或者SA账号被禁用. 2. 你进行了一些安全操作,把BuiltinAdm ...

  6. 【POJ3415】 Common Substrings (SA+单调栈)

    这道是求长度不小于 k 的公共子串的个数...很不幸,我又TLE了... 解法参考论文以及下面的链接 http://www.cnblogs.com/vongang/archive/2012/11/20 ...

  7. 【字符串】后缀数组SA

    后缀数组 概念 实际上就是将一个字符串的所有后缀按照字典序排序 得到了两个数组 \(sa[i]\) 和 \(rk[i]\),其中 \(sa[i]\) 表示排名为 i 的后缀,\(rk[i]\) 表示后 ...

  8. [luogu] P3809 【模板】后缀排序 (SA)

    板子,照着题解打的倍增版. #include <iostream> #include <cstdio> #include <cstring> using names ...

  9. 【MVC】ASP.NET MVC Forms验证机制

    http://www.cnblogs.com/bomo/p/3309766.html 随笔 - 121  文章 - 0  评论 - 92 [MVC]ASP.NET MVC Forms验证机制 ASP. ...

随机推荐

  1. iOS 多线程 之 GCD(大中枢派发)(二)

    本文接着上一篇讲.主要讲:dispatch_source. dispatch_source主要用户监听事件,可以监听如下事件 DISPATCH_SOURCE_TYPE_DATA_ADD DISPATC ...

  2. 连接mysql 报错 Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

    网上找不到  朋友说是因为非正常关机导致,mysql.server start 运行报错 ERROR! The server quit without updating PID file(): 解决办 ...

  3. Jenkins持续化集成

    Jenkins介绍 Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括: 1.持续的软件版本发布/测试项目. 2.监控外部调用执行的工作. 安装环境 操作系统:lin ...

  4. php扩展开发-全局变量

    //php_myext.hZEND_BEGIN_MODULE_GLOBALS(myext) unsigned long counter;//在这里定义需要的全局变量,可以多个,每个变量一行, ZEND ...

  5. dijkstra算法与优先队列

    这是鄙人的第一篇技术博客,作为算法小菜鸟外加轻度写作障碍者,写技术博客也算是对自己的一种挑战和鞭策吧~ 言归正传,什么是dijkstra算法呢? -dijkstra算法是一种解决最短路径问题的简单有效 ...

  6. C#学习你需要知道的---(For和Foreach)

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/52577283 作者:car ...

  7. python的高阶函数与匿名函数

    一.高阶函数的定义 高阶函数:就是把函数当成参数传递的一种函数,例如: def add(x,y,f): return f(x)+f(y) print(add(-8,11,abs) 结果:19 解释: ...

  8. 腾讯装扮下拉选项卡特效(QQ空间)

    <DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" ...

  9. ueditor搭建图片服务器

    最近用使用富文本编辑器,之前一直使用kindeditor和eWebEditor来着,有同事给推荐说使用百度推出的Ueditor,所以咯,自己新项目就将它引进来了,这里说一下心得, 说实话,Uedito ...

  10. Python之进程、线程、协程

    进程和线程的目的 进程和线程目的是为了:提高执行效率 现代操作系统比如Mac OS X,UNIX,Linux,Windows等,都是支持“多任务”的操作系统. 什么叫“多任务“呢?简单地说,就是操作系 ...