HDU3294 Girls & amp; #39; research

Source: Internet
Author: User
Tags cmath

HDU3294 Girls & #39; research
Girls 'researchtime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission (s): 1298 Accepted Submission (s): 493

Problem Description One day, sailormoon girls are so delighted that they intend to research about palindromic strings. Operation contains two steps:
First step: girls will write a long string (only contains lower case) on the paper. for example, "abcde", but 'A' inside is not the real 'A', that means if we define the 'B' is the real 'A ', then we can infer that 'C' is the real 'B', 'd is the real 'C '......, 'A' is the real 'Z'. According to this, string "abcde" changes to "bcdef ".
Second step: girls will find out the longest palindromic string in the given string, the length of palindromic string must be equal or more than 2.
Input contains multiple cases.
Each case contains two parts, a character and a string, they are separated by one space, the character representing the real 'A' is and the length of the string will not exceed 200000.All input must be lowercase.
If the length of string is len, it is marked from 0 to len-1.
Output Please execute the operation following the two 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 are several answers available, please choose the string which first appears.
Sample Input

B babd a abcd 

Sample Output
0 2 aza No solution! 

Author wangjing1111
Source 2010 "HDU-Sailormoon" Programming Contest
Question: Give a letter, for example, B. Then B is the real a, c is the real B, and then a string is provided, so that you can find the maximum echo string. Analysis: manacher algorithm, just change a little bit.
<Span style = "font-size: 18px; "> # include <iostream> # include <cstdio> # include <cstring> # include <stack> # include <queue> # include <map> # include <set> # include <vector> # include <cmath> # include <algorithm> using namespace std; const double eps = 1e-6; const double pi = acos (-1.0); const int INF = 0x3f3f3f3f; const int MOD = 1000000007; # define ll long # define CL (, b) memset (a, B, sizeof (a) # define MAXN 200010ch Ar ch, str [MAXN * 2], s [MAXN]; int p [MAXN * 2]; int pre, maxx; void init () {int I, l; CL (str, '\ 0'); // initialize str [0] =' $ '; str [1] =' # '; for (I = 0, l = 2; s [I]; I ++, l + = 2) {str [l] = s [I]; str [l + 1] = '#' ;}} void solve () {int id; int mx = 0; maxx = 0; for (int I = 1; str [I]; I ++) {if (mx> I) p [I] = p [2 * id-I]> (mx-I )? (Mx-I): p [2 * id-I]; else p [I] = 1; while (str [I-p [I] = str [I + p [I]) p [I] ++; if (p [I] + I> mx) {mx = p [I] + I; id = I;} if (maxx <p [I]) {// the location where the longest retrieval point is recorded. maxx = p [I]; pre = I; // cout <str <endl; printf ("maxx =" % d "pre =" % d \ n ", maxx, pre);"} = "" maxx --; = "" int = "" main () = "" {= "" while (scanf ("% c % s", & ch, s) = "= 2) "getchar (); =" "x =" ch "-=" "& #39; a & #39 ;; = "" for (int = "" I = "0;" s [I]; = "" I ++) = "" t = "s [I]" s [I] = "(t" + =" "26) % 26 =" "init (); =" "solve (); =" "r =" pre/2 "maxx =" "2 =" 1; = "" l = "r" if (maxx = ""> 1) {printf ("% d \ n", l, r ); for (int I = l; I <= r; I ++) printf ("% c", s [I]); printf ("\ n ");} else printf ("No solution! \ N ") ;}return 0 ;}</str <endl;> </algorithm> </cmath> </vector> </set> </map> </queue> </stack> </cstring> </cstdio> </iostream> </span>

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.