HDU3294 Girls '

Source: Internet
Author: User

This article is copyright ljh2000 and Blog Park is shared, welcome reprint, but must retain this statement, and give the original link, thank you for your cooperation.

This article ljh2000
Author Blog: http://www.cnblogs.com/ljh2000-jump/
Reprint please specify the source, infringement must investigate, retain the final interpretation right!

problem DescriptionOne day , Sailormoon Girls is so delighted the they intend to the, about palindromic strings. Operation contains, steps:
First Step:girls would write a long string (only contains lower case) on the paper. For example, "ABCDE", but ' a ' inside was not the real ' a ', so means if we define the ' B ' is the real ' a ' and then we can inf Er that ' C ' are the real ' B ', ' d ' is the real ' C ' ..., ' a ' is the real ' z '. According to this, the string "ABCDE" Changes to "Bcdef".
Second Step:girls'll find out the longest palindromic string in the given string, the length of palindromic string Must is equal or more than 2. 

InputInput contains multiple cases.
Each case contains parts, a character and a string, they is separated by one space, the character representing th e Real ' A ' is and the length of the string won't exceed 200000.All input must be lowercase.
If The length of string is Len, it's marked from 0 to len-1. 

OutputPlease execute the operation following the steps.
If You find one, output the start position and end position of palindromic string in a line, next line output the real palindromic string, or output "No solution!".
If There is several answers available, please choose the string which first appears. 

Sample Inputb babda ABCD 

Sample Output0 2azaNo solution!

Positive solution: Manacher

Problem Solving Report:

Manacher naked question.

According to test instructions to do it, pay attention to the odd and even of the situation discussion, of course, can not discuss, make a public formula can be.

began to not clear the subscript relationship, WA a pitch ...

 

It is made by Ljh2000#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio > #include <cmath> #include <algorithm>using namespace std;typedef long long ll;const int MAXN = 400011;int L En,n,cha,p[maxn],ans;char ch[maxn],s[maxn],h;inline int getint () {int w=0,q=0; char C=getchar (); while ((c< ' 0 ' | |    C> ' 9 ') && c!= '-') C=getchar (); if (c== '-') Q=1,c=getchar (); while (c>= ' 0 ' &&c<= ' 9 ') w=w*10+c-' 0 ', C=getchar (); return q?-w:w;} inline void Manacher () {memset (p,0,sizeof (P)); int maxr=0,id=0;for (int i=1;i<=n;i++) {if (I&LT;MAXR) p[i]=min (p[2* ID-I],MAXR-I); else p[i]=1;for (; I+p[i]<=n && S[i-p[i]]==s[i+p[i]];p [i]++); if (I+P[I]&GT;MAXR) {maxr=i+p[i]; id=i;}}} inline void work () {while (scanf ("%s", ch)!=eof) {h=ch[0]; scanf ("%s", ch); Len=strlen (ch); n=1;cha=h-' a '; s[0]= '% '; s[1]=   ‘#‘; for (int i=0;i<len;i++) {ch[i]-=cha; if (ch[i]< ' a ') ch[i]+=26;s[++n]=ch[i];s[++n]= ' # ';} Manacher (); Ans=1; int Pos=1;for (inT i=1;i<=n;i++) if (P[i]>ans) ans=p[i],pos=i;ans--; if (ans==1) {printf ("No solution!\n"); continue;} int L,r,mid;if (pos%2==0) {mid=pos/2-1; l=mid-ans/2; r=mid+ans/2;} else {mid=pos/2-1; l=mid-ans/2+1; r=mid+ans/2;} printf ("%d%d\n", L,r), for (int i=l;i<=r;i++) printf ("%c", Ch[i]);p rintf ("\ n");}}    int main () {work (); return 0;}

  

HDU3294 Girls '

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.