SPOJ220 relevant phrases of annihilation

Source: Internet
Author: User

http://www.spoj.com/problems/PHRASES/

Test instructions: Give n a string, find the n string inside there are 2 non-overlapping longest string length.

Idea: Two-point answer, and then you can hehe hey

PS: Spicy Chicken Topic ruined my youth, the first two points when the ANS did not assign the initial value of 0, the results will not be the answer when the output of strange digital t_t, in fact, the main blame I accidentally.

1#include <cstdio>2#include <iostream>3#include <cmath>4#include <cstring>5#include <algorithm>6 intlen,num[500005],ws[500005],wv[500005],wa[500005],wb[500005],h[500005],sa[500005],rank[500005];7 intf[500005][2],n,b[500005];8 Chars[500005];9 intRead () {Ten     intt=0, f=1;CharCh=GetChar (); One      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} A      while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} -     returnt*F; - } the BOOLcmpint*r,intAintBintl) { -     returnr[a]==r[b]&&r[a+l]==r[b+l]; - } - voidDaint*r,int*sa,intNintm) { +     int*t,*x=wa,*y=wb,i,j,k,p; -      for(i=0; i<m;i++) ws[i]=0; +      for(i=0; i<n;i++) x[i]=R[i]; A      for(i=0; i<n;i++) ws[x[i]]++; at      for(i=1; i<m;i++) ws[i]+=ws[i-1]; -      for(i=n-1; i>=0; i--) sa[--ws[x[i]]]=i; -      for(j=1, p=1;p <n;j*=2, m=p) { -          for(p=0, i=n-j;i<n;i++) y[p++]=i; -          for(i=0; i<n;i++)if(SA[I]&GT;=J) y[p++]=sa[i]-J; -          for(i=0; i<m;i++) ws[i]=0; in          for(i=0; i<n;i++) wv[i]=X[y[i]]; -          for(i=0; i<n;i++) ws[wv[i]]++; to          for(i=1; i<m;i++) ws[i]+=ws[i-1]; +          for(i=n-1; i>=0; i--) sa[--ws[wv[i]]]=Y[i]; -          for(t=x,x=y,y=t,i=1, x[sa[0]]=0, p=1; i<n;i++){ theX[SA[I]]=CMP (y,sa[i-1],sa[i],j)? p1:p + +; *         } $     }Panax Notoginseng } - voidCalint*r,intN) { the     inti,j,k=0; +      for(intI=1; i<=n;i++) rank[sa[i]]=i; A      for(intI=0; i<n;h[rank[i++]]=k) { the          for(k?k--:0, j=sa[rank[i]-1];r[j+k]==r[i+k];k++); +     } - } $ BOOLCheckintmid) { $     intL,r; -      for(intI=1; i<=len;i++){ -L=i; the          while(L<=len&&h[l]<mid) l++; -R=l;Wuyi          while(R<=len&&h[r]>=mid) r++; the          for(intj=1; j<=n;j++) f[j][0]=0x3f3f3f3f, f[j][1]=-0x3f3f3f3f; -          for(intj=l-1; j<=r-1; j + +){ Wu             intk=B[sa[j]]; -             if(k==n+1)Continue; Aboutf[k][0]=std::min (f[k][0],sa[j]); $f[k][1]=std::max (f[k][1],sa[j]); -         } -         intj=0; -          for(j=1; j<=n;j++){ A             if(f[j][0]==0x3f3f3f3f) Break; +             if(f[j][1]-f[j][0]&LT;MID) Break; the         } -         if(j>n)return 1; $I=R; the     } the     return 0; the } the voidsolve () { -     intL=1, r=20000, ans=0; in      while(l<=R) { the         intMid= (l+r) >>1; the         if(Check (mid)) ans=mid,l=mid+1; About         Elser=mid-1; the     } theprintf"%d", ans); the } + intMain () { -     intt=read (); the      while(t--){Bayilen=0; the         intn=read (); the          for(intI=1; i<=n;i++){ -scanf"%s", s+1); -             intLen=strlen (s+1); the              for(intj=1; j<=len;j++) thenum[len]=s[j],b[len++]=i; the             if(i<n) num[len]=290+i,b[len++]=n+1;  the         } -num[len]=0; b[len]=n+1; theDa (num,sa,len+1,310); the cal (Num,len); then=N;94 solve (); the     } the}

SPOJ220 relevant phrases of annihilation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.