HDU 3068 最长回文(manacher算法)
来源:互联网 发布:社区门诊软件 编辑:程序博客网 时间:2024/05/21 10:39
分析:
求最长回文子串 区别于最长回文子序列 manacher算法(网上都有详细解释) 直接上代码
AC代码:
#include <iostream>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <math.h>#include <vector>#include <stack>#include <queue>#include <map>#include <set>#include<list>#include <bitset>#include <climits>#include <algorithm>#define gcd(a,b) __gcd(a,b)#define FINfreopen("input.txt","r",stdin)#define FOUT freopen("output.txt","w",stdout)typedef long long LL;const LL mod=1e9+7;const int INF=0x3f3f3f3f;const double PI=acos(-1.0);using namespace std;char str[2200010];int p[2200010];int main (){//FIN;while (scanf("%s",&str)!=EOF){if (str[0]==' ')continue;int n=strlen(str);for (int i=n-1;i>=0;i--){// 处理串 str[(i+1)*2+1]='#';str[(i+1)*2]=str[i];}str[1]='#';str[0]='!';int id=0;int ans=0;memset(p,0,sizeof(p));for (int i=2;i<=n*2+1;i++){// 核心代码 p[i]=p[id]+id>i?min(p[2*id-i],p[id]+id-i):1;while (str[i-p[i]]==str[i+p[i]]) p[i]++;if (i+p[i]>id+p[id]) id=i;if (ans<p[i]) ans=p[i];}printf ("%d\n",ans-1);}return 0;}
阅读全文
0 0
- hdu 3068 最长回文 (manacher算法)
- HDU 3068 最长回文(Manacher 算法)
- hdu 3068 最长回文(manacher算法)
- Hdu 3068 最长回文(manacher算法)
- HDU 3068 最长回文(manacher算法)
- HDU 3068 最长回文(Manacher算法)
- hdu 3068 最长回文(manacher算法)
- HDU 3068 最长回文(manacher算法)
- Hdu 3068 最长回文 (manacher算法)
- HDU-3068-最长回文 (Manacher算法)
- hdu 3068 最长回文(manacher算法)
- HDU 3068 最长回文 Manacher算法
- hdu 3068 最长回文 manacher算法
- Hdu 3068 最长回文 Manacher 算法
- hdu 3068 最长回文 (Manacher算法)
- HDU 3068 最长回文 (Manacher算法)
- hdu-3068 最长回文 【Manacher算法】
- HDU 3068 最长回文 (manacher算法)
- 命令模式
- 2017面试题总结
- c语言写俄罗斯方块-简单易懂
- 编码习惯
- java UDP多线程回射服务器
- HDU 3068 最长回文(manacher算法)
- django框架对数据库的操作
- HDU 1005 Number Sequence 矩阵快速幂
- BZOJ 3239 [BSGS]
- C#中的回调函数:以最简单的方式讲解最实用的知识点
- 邝斌的ACM模板(相关公式)
- Activemq实现Mysql与SolrCloud同步策略
- 学习Halcon错误总结
- ubuntu定时执行任务crontab的使用