Hdu5384-hotaru ' s Problem-manacher

Source: Internet
Author: User
Tags cas

Find the close to three palindrome string, such as abccbaabc, shaped like the ABA format, where AB is a palindrome string. Calculates the longest length.

First use Manacher to deal with palindrome radius. Then we find two points, all even-numbered palindrome strings, and share the middle section.

Then get set to do it. = =

1#include <Set>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <queue>6 7 using namespacestd;8 9 Const intMAXN = 1e5+Ten;Ten intma[maxn<<2],mp[maxn<<2]; One Set<int>Pos; A  - structnode{ -     intmp,p; the node () {} -     BOOL operator< (ConstNode &AMP;RHS)Const -     { -         if(MP = = RHS.MP)returnp >RHS.P; +         Else returnMP <rhs.mp; -     } + }; A  atPriority_queue<node>PQ; - voidManacher (intS[],intlen) - { -     intL =0; -ma[l++] ='$'; -ma[l++] ='#'; in      for(intI=0; i<len;i++) -     { toma[l++] =S[i]; +ma[l++] ='#'; -     } theMA[L] =0; *     intMX =0, id =0; $      for(intI=0; i<l;i++)Panax Notoginseng     { -Mp[i] = mx > I? Min (mp[2*id-i],mx-i):1; the          while(Ma[i + mp[i]] [= ma[i-mp[i]]) mp[i]++; +         if(Mp[i] + i >mx) A         { theMX = mp[i] +i; +ID =i; -         } $     } $ } -  - intT,n; the intSAVE[MAXN]; - intMain ()Wuyi { thescanf"%d",&T); -     intCAS =0; Wu      while(t--) -     { Aboutscanf"%d",&N); $          for(intI=0; i<n;i++) scanf ("%d",&save[i]); - Manacher (save,n); -         intAns =0; - node tmp; A          while(!pq.empty ()) Pq.pop (); + pos.clear (); the          for(intI=0;i<2*n+1; i++) -         { $             if(Ma[i] = ='#'&& Mp[i] >1) the             { theTMP.MP =Mp[i]; theTMP.P =i; the Pq.push (TMP); -             } in         } the         intCNT =0; the         //for (int i=0;i<2*n+1;i++) printf ("%d\t", I); puts (""); About         //for (int i=0;i<2*n+1;i++) printf ("%c\t", ma[i]== ' # '? ') # ': ma[i]+ ' 0 '); Puts (""); the         //for (int i=0;i<2*n+1;i++) printf ("%d\t", Mp[i]); puts (""); the          while(!pq.empty ()) the         { +TMP =pq.top (); Pq.pop (); -             intCur = TMP.P,MP =tmp.mp; the             //printf ("cur:%d mp:%d\n", cur,mp);Bayi             intTmp_pos =0; the             if(CNT) the             { -Auto it = pos.lower_bound (cur-(mp-1) ); -  the                 //printf ("l:%d", *it); the                 if(It! = Pos.end () && *it >= cur-(mp-1) ans = max (ans,cur-*it); the  theit = pos.lower_bound (cur + (mp-1) ); it--; -                 //printf ("r:%d\n", *it); the                 if(It! = Pos.end () && *it <= cur+ (mp-1) ans = max (ans,*it-cur); the             } the Pos.insert (cur);94cnt++; the         } theprintf"Case #%d:%d\n", ++cas,ans/2*3); the     }98}

Hdu5384-hotaru ' s Problem-manacher

Contact Us

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.