Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我也是这样做的,但是RTE,不知道错那里,谁来帮我看看O(∩_∩)O谢谢了In Reply To:这个问题的确是要考虑的。 下面是我的解决方法 Posted by:ghost_wei at 2008-04-14 19:37:02 #include<iostream> using namespace std; const int maxn=400005; const int N=400005; int a[maxn]; int sa[maxn],rank[maxn],temp[maxn],h[maxn],Count[maxn],height[maxn]; int n,size; void Preprogress() { memset(temp,0,sizeof(temp)); int i,j,k; size=n+1<<2; memset(Count,0,N<<2); for(i=1;i<=n;i++) Count[a[i]]++; for(i=1;i<N;i++) Count[i]+=Count[i-1]; for(i=n;i>=1;i--) sa[Count[a[i]]--]=i; rank[sa[1]]=Count[1]=1; for(i=2;i<=n;i++) Count[rank[sa[i]]=rank[sa[i-1]]+int(a[sa[i]]!=a[sa[i-1]])]=i; for (k=1;k<n && rank[sa[n]]<n;k=k*2) { memcpy(temp,sa,size); for (i=n;i>=1;i--) if (temp[i]>k) sa[Count[rank[temp[i]-k]]--]=temp[i]-k; for (i=n-k+1;i<=n;i++) sa[Count[rank[i]]]=i; memcpy(temp,rank,size); rank[sa[1]]=Count[1]=1; for (i=2;i<=n;i++) Count[rank[sa[i]]=rank[sa[i-1]]+int(temp[sa[i]]!=temp[sa[i-1]] || temp[sa[i]+k]!=temp[sa[i-1]+k])]=i; } } int main() { scanf("%d",&n); int i; memset(a,0,sizeof(a)); for(i=n;i>=1;i--) scanf("%d",&a[i]); Preprogress(); int x,y; for(i=1;i<=n;i++) { if(sa[i]>2) { x=sa[i]; break; } } for(i=x;i<=n;i++) printf("%d\n",a[i]); for(i=x;i<=n;i++) a[i]=0; for(i=1;i<x;i++) a[x+i-1]=a[i]; n=(x-1)*2; Preprogress(); for(i=1;i<=n;i++) { if(sa[i]<x&&sa[i]>1) { y=sa[i]; break; } } for(i=y;i<x;i++) printf("%d\n",a[i]); for(i=1;i<y;i++) printf("%d\n",a[i]); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator