...又是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. DB总结1

    DBA  重构 data  new york   committee   cobol codasyl  journal DDL  DML    关系演算  域关系演算语言(QBE)  元祖关系演算语言 ...

  2. FAT32中文版分析+补充(2)

    从Offset 36(0x24)开始FAT12/16的内容开始区别于FAT32,现在分两个表格列出来,下表为FAT12/16的内容: 名称 Offset(Byte) 大小(Byte) 描述 BS_dr ...

  3. 1237: [SCOI2008]配对

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1789  Solved: 715[Submit][Status][Discuss] Descripti ...

  4. 基于 win7下虚拟机的 GNSS-SDR安装过程

    最近在安装 GNSS-SDR软件时,遇到了很多问题,这里回顾了我的安装过程,罗列了所遇到的问题和解决办法.希望后来者不要再踩这些坑了! 首先,在官方文档中看到,GNSS-SDR目前并不支持直接在 Wi ...

  5. MySQL主从复制读写分离如何提高从库性能-实战

    在做主从读写分离时候,需要注意主从的一些不同参数设置,来提高从库的性能,提高应用读取数据的速度,这样做很有必要的. 做读写分离复制主从参数不同设置如下(需要根据自己应用实际情况来设置): parmet ...

  6. .NET 客户IP地址捕捉

    MVC模式下要获取客户IP可以在ActionFilterAttribute中进行拦截 filterContext.HttpContext.Request.UserHostAddress 同样,在Web ...

  7. ethereum(以太坊)(十一)--字节数组(二)

    pragma solidity ^0.4.0; contract test { uint [5] T =[1,2,3,4,5] ;//固定长度的数组:可修改数组内值大小,不支持push,不可更改长度 ...

  8. php中const与static的区别与使用(转)

    首先关于const 在php的类内部只可以修饰成员属性,不可以修饰方法,如下:   class Test{   const PATH = 'c/';//修饰常量   const function te ...

  9. photoshop入门笔记2:PS箭头的制作

    ---恢复内容开始--- 1.     首先打开ps软件,在ps里新建一个画布这里就500*500,可以随意. 2.然后在ps软件界面上的工具栏里找到‘直线工具’,如图. 3.选择好工具之后,在ps软 ...

  10. Python分布式爬虫抓取知乎用户信息并进行数据分析

    在以前的文章中,我写过一篇使用selenium来模拟登录知乎的文章,然后在很长一段时间里都没有然后了... 不过在最近,我突然觉得,既然已经模拟登录到了知乎了,为什么不继续玩玩呢?所以就创了一个项目, ...