poj3974 Palindrome(manacher)
来源:互联网 发布:go并发编程实战 源码 编辑:程序博客网 时间:2024/05/22 13:02
题目点我点我点我
题目大意:求最长回文串。
解题思路:跟上篇一样马拉车模版题。
/* ***********************************************┆ ┏┓ ┏┓ ┆┆┏┛┻━━━┛┻┓ ┆┆┃ ┃ ┆┆┃ ━ ┃ ┆┆┃ ┳┛ ┗┳ ┃ ┆┆┃ ┃ ┆┆┃ ┻ ┃ ┆┆┗━┓ 马 ┏━┛ ┆┆ ┃ 勒 ┃ ┆ ┆ ┃ 戈 ┗━━━┓ ┆┆ ┃ 壁 ┣┓┆┆ ┃ 的草泥马 ┏┛┆┆ ┗┓┓┏━┳┓┏┛ ┆┆ ┃┫┫ ┃┫┫ ┆┆ ┗┻┛ ┗┻┛ ┆************************************************ */#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>using namespace std;#define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)const int inf_int = 2e9;const long long inf_ll = 2e18;#define inf_add 0x3f3f3f3f#define mod 1000000007#define LL long long#define ULL unsigned long long#define MS0(X) memset((X), 0, sizeof((X)))#define Sd(X) int (X); scanf("%d", &X)#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)const int maxn = 3e6;char s[maxn],str[maxn];int len1,len2,p[maxn],ans;void init(){ str[0] = '$'; str[1] = '#'; for(int i=0;i<len1;i++) { str[i*2+2] = s[i]; str[i*2+3] = '#'; } len2 = len1*2 + 2; str[len2] = '*';}void manacher(){ int id=0,mx=0; for(int i=0;i<len2;i++) { if(mx>i)p[i] = min(p[id*2-i],mx-i); else p[i] = 1; for(;str[i-p[i]]==str[i+p[i]];p[i]++); if(p[i]+i>mx) { mx = p[i] + i; id = i; } }}int main(){//freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout);ios::sync_with_stdio(0);cin.tie(0);int cas = 1;while(~scanf("%s",s)) { if(s[0]=='E')break; len1 = strlen(s); init(); manacher(); ans = 0; for(int i=0;i<len2;i++)ans = max(ans,p[i]); cout<<"Case "<<cas++<<": "<<ans-1<<endl; } return 0;}
0 0
- poj3974 Palindrome(manacher)
- POJ3974 Palindrome(Manacher算法)
- poj3974:Palindrome(manacher模板)
- Palindrome(poj3974)(manacher算法)
- POJ3974 Palindrome (manacher算法)
- 【POJ3974】【Palindrome】【Manacher裸题】
- POJ3974 Palindrome(Manacher)
- [学习][poj3974]manacher Palindrome
- poj3974 Palindrome(manacher)
- poj3974 Palindrome,回文串,Manacher
- hdu3068 最长回文 poj3974 Palindrome(Manacher算法)
- poj3974(manacher)
- 【POJ3974】Palindrome Manacher、模板题 裸题
- POJ3974 Palindrome 解题报告【字符串】【Manacher】
- POJ3974 Palindrome
- poj3974 Palindrome
- poj3974 Palindrome
- POJ3974 Palindrome
- MYSQL-----数据查询(续)
- 如何快糙好猛的使用Shiqi.Yu老师的公开人脸检测库(附源码)
- 第二部分:Shader Authoring with HLSL(使用HLSL编写开发shader)
- [JZOJ3466] 选课
- Error:Maven Resources Compiler: Failed to copy 'XXX' to 'YYY': YYY (拒绝访问。)
- poj3974 Palindrome(manacher)
- Qt Style Sheet实践(三):QCheckBox和QRadioButton
- spring 9 bean配置--通过工厂方法(静态工厂方法&实例工厂方法
- 生活随笔:广州下了一场雨,手游新政策来了
- QT生成PDF
- asdasd
- js一些代码
- intellij idea module设置 dependencies的export
- Apache POI 3.14 教程(2)