【POJ3294】 Life Forms(SA)

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

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

const maxn=100419;
var
 x,y,rank,sa,c,col,h,rec:array[0..maxn] of longint;
 pd:array[0..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:=1;
 while p<n do
  begin
   fillchar(c,sizeof(c),0);
   for i:= 1 to n-p do y[i]:=rank[i+p];
   for i:= n-p+1 to n do y[i]:=0;
   for i:= 1 to n do inc(c[y[i]]);
   for i:= 1 to n do inc(c[i],c[i-1]);
   for i:= 1 to n do
    begin
     sa[c[y[i]]]:=i;
     dec(c[y[i]]);
    end;
   fillchar(c,sizeof(c),0);
   for i:= 1 to n do x[i]:=rank[i];
   for i:= 1 to n do inc(c[x[i]]);
   for i:= 1 to n do inc(c[i],c[i-1]);
   for i:= n downto 1 do
    begin
     y[sa[i]]:=c[x[sa[i]]];
     dec(c[x[sa[i]]]);
    end;
   for i:= 1 to n do sa[y[i]]:=i;
   tot:=1;
   rank[sa[1]]:=1;
   for i:= 2 to n do
    begin
     if (x[sa[i]]<>x[sa[i-1]]) or (x[sa[i]+p]<>x[sa[i-1]+p]) then inc(tot);
     rank[sa[i]]:=tot;
    end;
   p:=p<<1;
  end;
 for i:= 1 to n do sa[rank[i]]:=i;
end;

procedure makeh;
var i,p,j:longint;
begin
 p:=0; h[1]:=0;
 for i:= 1 to n do
  begin
   p:=max(p-1,0);
   if rank[i]=1 then continue;
   j:=sa[rank[i]-1];
   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>>1;
 readln(s);
 tot:=1;
 maxlen:=length(s);
 for i:= 1 to maxlen do col[i]:=1;
 for i:= 2 to n do
  begin
   readln(s1);
   s:=s+'#';
   maxlen:=max(length(s1),maxlen);
   inc(tot);
   for j:= length(s)+1 to length(s)+length(s1) do col[j]:=tot;
   s:=s+s1;
  end;
 n:=length(s);
 fillchar(c,sizeof(c),0);
 for i:= 1 to n do x[i]:=ord(s[i]);
 for i:= 1 to n do inc(c[x[i]]);
 for i:= 1 to 128 do inc(c[i],c[i-1]);
 for i:= 1 to n do
  begin
   sa[c[x[i]]]:=i;
   dec(c[x[i]]);
  end;
 tot:=1;
 rank[sa[1]]:=1;
 for i:= 2 to n do
  begin
   if x[sa[i]]<>x[sa[i-1]] 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[0]:=true; tot:=0; cnt:=0;
 if not pd[sa[1]] then inc(tot);
 pd[sa[1]]:=true;
 for i:= 2 to n do
  begin
   if h[i]<x then
    begin
     if tot>k then
      begin
       inc(cnt);
       rec[cnt]:=i-1;
      end;
     tot:=0;
     fillchar(pd,sizeof(pd),false);
     pd[0]:=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-1;
  end;
 if cnt>0 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+1)];
 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:=1; r:=maxlen;  ans:=0;
 while l<=r do
  begin
   mid:=(l+r)>>1;
   if check(mid) then
    begin
     ans:=mid;
     l:=mid+1;
    end
   else r:=mid-1;
  end;
 fillchar(pd,sizeof(pd),false);
 if ans=0 then
  begin
   writeln('?');
   exit;
  end;
 qsort(1,cnta);
 for i:= 1 to cnta do writeln(copy(s,sa[rec[i]],ans));
end;

Begin
 readln(n);
 while n<>0 do
  begin
   init;
   solve;
   writeln;
   readln(n);
  end;
End.

 

转载于:https://www.cnblogs.com/EC-Ecstasy/p/4175440.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测(Object Detection)是计算机视觉领域的一个核心问题,其主要任务是找出图像中所有感兴趣的目标(物体),并确定它们的类别和位置。以下是对目标检测的详细阐述: 一、基本概念 目标检测的任务是解决“在哪里?是什么?”的问题,即定位出图像中目标的位置并识别出目标的类别。由于各类物体具有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具挑战性的任务之一。 二、核心问题 目标检测涉及以下几个核心问题: 分类问题:判断图像中的目标属于哪个类别。 定位问题:确定目标在图像中的具体位置。 大小问题:目标可能具有不同的大小。 形状问题:目标可能具有不同的形状。 三、算法分类 基于深度学习的目标检测算法主要分为两大类: Two-stage算法:先进行区域生成(Region Proposal),生成有可能包含待检物体的预选框(Region Proposal),再通过卷积神经网络进行样本分类。常见的Two-stage算法包括R-CNN、Fast R-CNN、Faster R-CNN等。 One-stage算法:不用生成区域提议,直接在网络中提取特征来预测物体分类和位置。常见的One-stage算法包括YOLO系列(YOLOv1、YOLOv2、YOLOv3、YOLOv4、YOLOv5等)、SSD和RetinaNet等。 四、算法原理 以YOLO系列为例,YOLO将目标检测视为回归问题,将输入图像一次性划分为多个区域,直接在输出层预测边界框和类别概率。YOLO采用卷积网络来提取特征,使用全连接层来得到预测值。其网络结构通常包含多个卷积层和全连接层,通过卷积层提取图像特征,通过全连接层输出预测结果。 五、应用领域 目标检测技术已经广泛应用于各个领域,为人们的生活带来了极大的便利。以下是一些主要的应用领域: 安全监控:在商场、银行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值