HDU 4513 吉哥系列故事——完美队形II
从中间向两边递减的回文,特判一下就好
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 const int qq=100000+10; 7 int que[qq*2]; 8 int p[qq*2]; 9 int main() 10 { 11 int t;scanf("%d",&t); 12 while(t--){ 13 int n;scanf("%d",&n); 14 int w=2; 15 que[0]=20; 16 que[1]=1000; 17 for(int i=0;i<n;++i){ 18 scanf("%d",&que[w++]); 19 que[w++]=1000; 20 } 21 n=n*2+1; 22 int maxn=0; 23 int mx=0; 24 int id; 25 //for(int i=0;i<=n;++i) 26 // printf("%d ",que[i]); 27 // printf("\n"); 28 for(int i=1;i<n;++i){ 29 if(mx>i) 30 p[i]=min(mx-i,p[2*id-i]); 31 else 32 p[i]=1; 33 while(que[i+p[i]]==que[i-p[i]]&&(que[i-p[i]]==1000||que[i-p[i]]<=que[i-p[i]+2])) 34 p[i]++; 35 if(i+p[i]>mx){ 36 mx=i+p[i]; 37 id=i; 38 } 39 if(p[i]-1>maxn) 40 maxn=p[i]-1; 41 //printf("%d ",p[i]); 42 } 43 //printf("\n"); 44 printf("%d\n",maxn); 45 } 46 return 0; 47 }