hihocoder1032(最长回文子串manacher算法)
来源:互联网 发布:数组的push和pop 编辑:程序博客网 时间:2024/04/29 03:43
题目连接:点击打开链接
解题思路:
manacher算法的模板题。
完整代码:
#include <algorithm>#include <iostream>#include <cstring>#include <complex>#include <cstdio>#include <string>#include <cmath>#include <queue>using namespace std;typedef unsigned long long LL;const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const double EPS = 1e-9;const double PI = acos(-1.0); //M_PI;const int maxn = 2000001;int n;char s[maxn] , t[maxn];int len[maxn];void manacher(char t[]){ int t_len = strlen(t); int mx = 0 , id; for(int i = 1 ; i < t_len ; i ++) { if(mx > i) len[i] = min(len[id * 2 - i] , mx - i); else len[i] = 1; while(t[i + len[i]] == t[i - len[i]]) len[i] ++; if(len[i] + i > mx) { mx = len[i] + i; id = i; } }}void solve(char s[]){ int s_len = strlen(s); int t_len = s_len * 2 + 2; t[0] = '+'; for(int i = 0 ; i < t_len ; i ++) { t[i * 2 + 1] = '#'; t[i * 2 + 2] = s[i]; } manacher(t); int ans = -INF; for(int i = 1 ; i < t_len ; i ++) ans = max(ans , len[i]); printf("%d\n" , ans - 1);}int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif while(~scanf("%d",&n)) { for(int i = 0 ; i < n ; i ++) { scanf("%s" , s); solve(s); } } return 0;}
0 0
- hihocoder1032(最长回文子串manacher算法)
- manacher hihoCoder1032 最长回文子串
- hihocoder1032最长回文子串 [Manacher]
- hihocoder1032 最长回文子串
- [hihocoder1032]最长回文子串
- 最长回文子串LPS(Hihocoder1032)
- Manacher算法求最长回文子串
- Manacher算法求最长回文子串
- 最长回文子串(Manacher算法)
- Manacher算法 最长回文子串
- 最长回文子串的manacher算法
- 最长回文子串,Manacher算法
- Poj3974 最长回文子串 Manacher算法
- 最长回文子串 manacher算法
- Manacher算法(最长子回文串)
- HDU3068(最长回文子串manacher算法)
- 最长回文子串 用manacher算法
- hiho1032 : 最长回文子串 Manacher算法
- matlab 类编写
- how to kill hive server and start
- Myeclipse、STS等IDE中项目validating问题
- android进阶篇二 Android硬件加速详解 Hardware Acceleration
- 关于android屏幕分辨率
- hihocoder1032(最长回文子串manacher算法)
- segment文字颜色,选中颜色,未选中颜色设置
- 程序员必读书籍及导读指南
- 一、进制数
- NYOJ 6 喷水装置(一)
- MongoDB简介
- Linux PCI/PCI-E设备配置空间读取与修改
- GitHub控件之BadgeView(数字提醒)
- 图片的处理