zoukankan      html  css  js  c++  java
  • HDU3068最长回文 题解

    题目大意:

      求字符串的最长回文子串的长度。

    思路:

      Manacher板题,Hash可能会T。要学习Manacher,可参考https://www.felix021.com/blog/read.php?2040

    代码:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #define M 350000
     5 using namespace std;
     6 
     7 int r[M];
     8 char s[M],str[M];
     9 
    10 int main()
    11 {
    12     while (scanf("%s",s)!=EOF)
    13     {
    14         int i,k,l=strlen(s),ans=0,maxr=0;
    15         for (str[0]='$',i=l;i>=0;i--) str[i+i+2]=s[i],str[i+i+1]='#';
    16         for (i=2;i<=l+l;i++)
    17         {
    18             r[i]=maxr>i?min(r[k+k-i],maxr-i):1;
    19             for (;str[i-r[i]]==str[i+r[i]];r[i]++);
    20             if (i+r[i]>maxr) maxr=i+r[i],k=i;
    21             ans=max(r[i],ans);
    22         }
    23         printf("%d
    ",ans-1);
    24     }
    25     return 0;
    26 }
    我一直在繁华的苍凉中徘徊着,用一颗OI的心寻找着生命和宇宙的美妙与玄奥。
  • 相关阅读:
    python django day 1
    C# 日常
    C# NPOI使用
    SharpZipLib 压缩ZIP导出
    JSON劫持
    跨站请求伪造CSRF或XSRF
    跨站脚本XSS安全
    会话窃取
    Cookie
    Promise -ES6
  • 原文地址:https://www.cnblogs.com/HHshy/p/5734126.html
Copyright © 2011-2022 走看看