HDU 3294 Girls’ research Manacher

题目中有一个规律的字母替换,输出最长回文(len>=2)的起始点和终点和替换后的回文。

#include
#include
#include
#include
#include
#include

using namespace std;

const int MAX=222222<<1;
char Str[MAX],Ch;
int Len;
int Radius[MAX];

void Manacher()
{
    Radius[0]=1;
    for (int i=1,k=0;iif (k+Radius[k]-11;
        else Radius[i]=min(Radius[2*k-i],k+Radius[k]-i);
        while (Str[i-Radius[i]]==Str[i+Radius[i]]) Radius[i]++;
        if (k+Radius[k]-11) k=i;
    }
}

int main()
{
    cin.sync_with_stdio(false);
    while (cin>>Ch>>Str)
    {
        int temp=Ch-'a';
        Len=strlen(Str);
        for (int i=Len;i>=0;i--)
        {
            Str[i*2+1]='#';
            Str[i*2+2]=(Str[i]-'a'-temp+26)%26+'a';
        }
        Len=Len*2+2;
        Str[0]='*',Str[Len]='\0';
        Manacher();
        int Max=1,Index=-1;
        for (int i=0;iif (Radius[i]-1>Max)
                Max=Radius[i]-1,Index=i;
        if (Index!=-1)
        {
            int Start=(Index-Max+1-2)/2,End=(Index+Max-1-2)/2;
            cout<' '<'\n';
            for (int i=Index-Max+1;i<=Index+Max-1;i++)
                if (Str[i]!='#')
                    cout<cout<<'\n';
        }
        else
            cout<<"No solution!\n";
    }
    return 0;
}

你可能感兴趣的:(acm)