吉哥系列故事——完美队形II HDU - 4513

//主要中间的-1以及起点为无穷大,,因为起始递增的话需要不符合递增条件

#include 
#include 
#include 
#include 

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 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

你可能感兴趣的:(HDU,Manacher)