HDU3068 longest reply

Source: Internet
Author: User

HDU3068 longest reply
Maximum retrieval Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission (s): 13605 Accepted Submission (s): 4947
The Problem Description is a string consisting of lowercase English characters a, B, c... y, and z. Evaluate the length of the longest return string in S.
The same string is used for both positive and negative reads, such as aba and abba.
There are multiple Input cases in each group. Each Input is a string consisting of lowercase letters a, B, c... y, and z.
The two cases are separated by empty rows (this empty row does not need to be processed)
String Length len <= 110000
An integer x in each line of Output corresponds to a group of cases, which indicates the maximum length of the input string in the group of cases.

Sample Input

Aaaa abab 

Sample Output
4 3 

Source 2009 Multi-University Training Contest 16-Host by NIT
Analysis: The template Question of the manacher algorithm.
<span style="font-size:18px;">#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define MAXN 110010char s[MAXN],str[MAXN*2];int p[MAXN*2];int n;void init(){    int i;    str[0] = '@'; str[1] = '#';    for(i=0,n=2; s[i]; i++,n+=2)    {        str[n] = s[i];        str[n+1] = '#';    }    str[n] = 0;}int solve(){    int id;    int mx=0;    int ans = 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(ans < p[i]) ans = p[i];    }    return ans-1;}int main(){    while(scanf("%s",s)!=-1)    {        init();        printf("%d\n",solve());    }}</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.