HDU 3068 最长回文串
来源:互联网 发布:软件培训价格表 编辑:程序博客网 时间:2024/04/29 18:00
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068
分析:参考manacher算法http://wenku.baidu.com/view/3031d2d3360cba1aa811da42.html
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <iostream>using namespace std;const int maxn = 110000 + 10;char str[maxn];char str1[maxn*2];int p[maxn*2];int n;void manacher() { memset(p,0,sizeof(p)); int MaxId=-1; int id; for(int i=1; str1[i]; ++i) { if(MaxId>i) p[i]=min(p[2*id-i], MaxId-i); else p[i]=1; while(str1[i+p[i]]==str1[i-p[i]])p[i]++; if(p[i]+i>MaxId) MaxId=p[i]+i, id=i; }}void change() { str1[0]='$'; str1[1]='#'; for(int i=0;i<n; ++i) { str1[i*2+2]=str[i]; str1[i*2+3]='#'; }}int main() { while(scanf ("%s", str) != EOF) { memset(str1, '\0', sizeof(str1)); n=strlen(str); change(); manacher(); int ma = -1; for(int i = 0; str1[i]; ++i) if(p[i]-1>ma)ma=p[i]-1; printf ("%d\n", ma); } return 0;}
- HDU 3068 最长回文 [Manacher回文串]
- HDU 3068最长回文串
- HDU 3068 最长回文串
- HDU 3068 最长回文串
- HDU 3068 最长回文串
- hdu 3068 最长回文串
- HDU-3068 最长回文串
- hdu 3068 最长回文 + 最长回文串算法
- hdu 3068 最长回文(manacher&最长回文子串)
- hdu 3068 最长回文(最长回文子串 manacher算法)
- HDU 3068 最长回文(求最长回文子串)
- HDU 3068 最长回文 最长回文子串
- HDU 3068 ( 最长回文 )
- HDU-3068 最长回文
- hdu 3068 最长回文
- Hdu 3068 最长回文
- HDU 3068 最长回文
- HDU-3068-最长回文
- sed命令详解
- mysql_修改密码
- sdut.acm2012级《程序设计基础Ⅱ)》_链表 金牌、银牌、铜牌
- 线段树(端点更新) hdu-4521 小明系列问题——小明序列
- java读取Xml几种方式
- HDU 3068 最长回文串
- Linux应用总结(1):自动删除n天前日志
- Java编程(位运算符)
- Android开发笔记
- 公司使用的jqgrid的方法列表
- Item显示个数
- MySQL的一些简单语法(5)-视图
- 使用COMPC创建库
- 人机交互复习