吉哥系列故事——完美队形II HDU - 4513
作者:互联网
//主要中间的-1以及起点为无穷大,,因为起始递增的话需要不符合递增条件
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAXN=1e6+10;
int h[MAXN];
int len=0;
const int inf = 0x3f3f3f3f;
int Manacher() {
int id = 0;
int Mx = 0;
int MAX = 0;
int p[len+1];
for(int i=1; i<len; i++) {
if(Mx > i) p[i] = min(p[2 * id - i], Mx - i);
else p[i] = 1 ;
while(h[i-p[i]] == h[i+p[i]] && h[i-p[i]] <= h[i-p[i]+2]) p[i]++;
if(p[i]+i > Mx) {
Mx = p[i] + i;
id = i;
}
MAX = max(MAX, p[i]-1);
}
return MAX;
}
int main()
{
int T, n;
scanf("%d",&T);
while(T--) {
scanf("%d", &n);
len = 0;
h[len++] = inf;
h[len++] = -1;
for(int i=0; i<n; i++){
scanf("%d", &h[len++]);
h[len++]=-1;
}
printf("%d\n", Manacher());
}
return 0;
}
,
标签:HDU,int,4513,len,id,II,MAX,include,Mx 来源: https://blog.csdn.net/KLFTESPACE/article/details/100836307