# HDU 3068 Manacher algorithm

Source: Internet
Author: User

Test instructions: Find the longest palindrome string, template problem

`1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <queue>7#include <map>8 using namespacestd;9 #defineMOD 1000000007Ten Const intinf=0x3f3f3f3f; One Const Doubleeps=1e-5; A #defineCL (a) memset (A,0,sizeof (a)) - #defineTS printf ("*****\n"); - intN,m,tt;Const intmaxn=110010; the Charma[maxn*2]; - intmp[maxn*2]; - voidManacher (CharS[],intlen) - { +     intL=0; -ma[l++]='\$'; +ma[l++]='#'; A      for(intI=0; i<len;i++) at     { -ma[l++]=S[i]; -ma[l++]='#'; -     } -ma[l]=0; -     intmx=0, id=0; in      for(intI=0; i<l;i++) -     { toMp[i]=mx>i?min (mp[2*id-i],mx-i):1; +          while(Ma[i+mp[i]]==ma[i-mp[i]]) mp[i]++; -         if(i+mp[i]>mx) the         { *mx=i+Mp[i]; \$Id=i;Panax Notoginseng         } -     } the } + CharS[MAXN]; A intMain () the { + #ifndef Online_judge -Freopen ("1.in","R", stdin); \$     #endif \$      while(SCANF ("%s", s) = =1) -     { -         intlen=strlen (s); the Manacher (S,len); -         intans=0;Wuyi          for(intI=0;i<2*len+2; i++) theAns=max (ans,mp[i]-1); -printf"%d\n", ans); Wu     } -     return 0; About}`

HDU 3068 Manacher algorithm

Related Keywords:

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.