HDU3068[最长回文]--Manacher
来源:互联网 发布:黑暗之魂淘宝 编辑:程序博客网 时间:2024/05/28 05:15
【链接】
hdu3068
【题目大意】
Manacher模板裸题。
【解题报告】
Manacher模板裸题。
#include<cstdio>#include<cstring>#define min(x,y) (x)<(y)?(x):(y)#define max(x,y) (x)>(y)?(x):(y)using namespace std;const int maxn=110005,maxm=220005;int p[maxm];char s[maxn],c[maxm];bool Sread(char *s){ char ch=getchar(); int len=1; while (ch<'a'||ch>'z') {if (ch==EOF) return 0; ch=getchar();} while (ch>='a'&&ch<='z') s[len++]=ch,ch=getchar(); s[len]='\0'; return 1;}int Manacher(char *s){ int len=strlen(s+1); for (int i=1; i<=len; i++) c[2*i-1]='~',c[2*i]=s[i]; c[len=2*len+1]='~'; int Pos=0,R=0,MAX=0; for (int i=1; i<=len; i++) { if (i<R) p[i]=min(p[2*Pos-i],R-i); else p[i]=1; while (1<=i-p[i]&&i+p[i]<=len&&c[i-p[i]]==c[i+p[i]]) p[i]++; if (i+p[i]>R) {R=i+p[i]; Pos=i;} MAX=max(MAX,p[i]-1); } return MAX;}int main(){ freopen("3068.in","r",stdin); freopen("3068.out","w",stdout); while (Sread(s)) printf("%d\n",Manacher(s)); return 0;}
阅读全文
1 0
- 【HDU3068】最长回文【manacher】
- HDU3068 最长回文 manacher
- 【HDU3068】最长回文【Manacher】
- 最长回文 hdu3068 manacher
- Manacher HDU3068 最长回文
- HDU3068[最长回文]--Manacher
- hdu3068(最长回文manacher)
- 【Manacher算法】hdu3068 最长回文
- 【HDU3068】【最长回文】【Manacher裸题】
- HDU3068最长回文 Manacher算法
- hdu3068 最长回文--Manacher算法
- HDU3068 最长回文 manacher模板
- Manacher(hdu3068最长回文)
- hdu3068 最长回文(manacher)
- HDU3068 最长回文(manacher)
- HDU3068(最长回文子串manacher算法)
- hdu3068 最长回文(manacher 算法)
- hdu3068最长回文(manacher算法)
- java中i++和++i的深层理解
- mybatis pagehelper 5.0.0插件的配置方法
- struts2.5.12版本使用action通配符提示找不到action的问题
- java 并发
- 对MySQL中JSON数据类型的操作和分析
- HDU3068[最长回文]--Manacher
- 四、c++中的算法--变动性算法---赋值
- 装配Bean
- HDU 4561连续最大积(模拟题)
- 四、c++中的算法--变动性算法---替换
- 关于Clone克隆对象的讲解
- bzoj 2330(差分约束)
- 四、c++中的算法--变动性算法---逆转
- c# DataTime.toString()的显示精度问题