hdu3068 最长回文子串问题.
来源:互联网 发布:淘宝商家提供发票不符 编辑:程序博客网 时间:2024/05/22 21:19
O(n)法求最长回文串,代码如下
#include<stdio.h>#include<stdlib.h>#include<string.h>int p[310000];char str[310000];int min(int a,int b){ return a<b?a:b;}int kp(int n){ int i; int max=0; int id,ans=1;; for(i=1;i<n;i++) { if(max>i) p[i]=min(p[2*id-i],max-i); else p[i]=1; while(str[i+p[i]]==str[i-p[i]]) p[i]++; if(p[i]+i>max) { max=p[i]+i; id=i; } if(p[i]>ans) ans=p[i]; } return ans-1;}int main(){ int n,i; char s[310000]; while(~scanf("%s",s)) { memset(p,0,sizeof(p)); n=strlen(s); str[0]='$'; str[1]='#'; for(i=0;i<n;i++) { str[i*2+2]=s[i]; str[i*2+3]='#'; } n=n*2+2; str[n]=0; int l=kp(n); printf("%d\n",l); } return 0;}
我也是从网上看大神们写的,最长回文子串问题详细求解过程以及解释请点击下面连接
最长回文子串问题
0 0
- hdu3068 最长回文子串问题.
- HDU3068(最长回文子串manacher算法)
- hdu3068 最长回文 (最长回文子串)
- 【最长回文子串】HDU3068最长回文【Manacher算法】
- hdu3068 最长回文串
- HDU3068 URAL1297 Manacher求最长回文子串
- 最长回文子串 HDU3068 POJ3974 CF.7D
- manacher算法求最长回文子串(hdu3068)
- hdu3068(最长回文串)
- HDU3068-最长回文---O(n)时间求最长回文子串
- Manacher算法,O(n)回文子串算法 以及模板题HDU3068最长回文串
- hdu3068 最长回文串 (manacher)
- HDU3068-manacher算法-最长回文串
- HDU3068 最长回文
- hdu3068 最长回文
- hdu3068---最长回文
- 【HDU3068】最长回文【manacher】
- HDU3068 最长回文
- 某资产配置平台系统方案建设规划
- ServletContext加载资源文件的方式
- 【LeetCode】1. Two Sum 解题报告
- 公证通Factom白皮书
- CentOS7 安装Sublime Text 3
- hdu3068 最长回文子串问题.
- (创建型模式)BUILDER——建造者模式(生成器模式)
- (行为型模式)STATE——状态模式
- SonarQube代码质量管理平台安装与使用
- 计算机图形学(二)输出图元_11_OpenGL多边形填充区函数(上)
- 从一条石家庄到长沙的最好路线
- (结构型模式)ADAPTER——适配器模式
- View的滑动冲突
- install tomcat on mac