Manacher算法(最长子回文串)
来源:互联网 发布:三线开花及选股源码 编辑:程序博客网 时间:2024/04/29 14:26
HDU3068 POJ3974
#include <iostream>#include <cstdio>#include <algorithm>#include <map>#include <vector>#include <set>#include <string>#include <cstring>#define INT_MIN 0x80000000#define INT_MAX 0xffffffff#define N 1001000#define MAX(a,b) (a)>(b)?(a):(b)#define MIN(a,b) (a)<(b)?(a):(b)#define LL long long#define debug(x) cout<<#x<<":"<<(x)<<endl;using namespace std;char s[N<<1];int p[N<<1];int main(){ //freopen("1.txt", "r", stdin); //freopen("11.txt", "w", stdout); //ios::sync_with_stdio(false); while( ~scanf("%s", s) ) { int len = strlen(s); int id = 0 , max_len = 0; for(int i=len; i>=0; i--) { s[i+i+2] = s[i]; s[i+i+1] = '#'; } s[0] = '*'; for(int i=2; i<2*len+1; i++) { if(p[id]+id>i) p[i] = min(p[id-(i-id)], p[id]-(i-id)); else p[i] = 1; while( s[i-p[i]] == s[i+p[i]] ) ++p[i]; if( id+p[id] < i+p[i] ) id = i; if( max_len < p[i] ) max_len = p[i]; } printf("%d\n", max_len-1); } return 0;}
0 0
- Manacher算法(最长子回文串)
- 最长回文子串(Manacher算法)
- 最长回文子串(Manacher算法)
- 最长回文子串算法-- Manacher算法--O(n)
- Manacher算法--O(n)最长回文子串算法
- Manacher算法求最长回文子串
- Manacher算法求最长回文子串
- 最长回文子串(Manacher算法)
- Manacher算法 最长回文子串
- 最长回文子串的manacher算法
- 最长回文子串,Manacher算法
- Poj3974 最长回文子串 Manacher算法
- 最长回文子串 manacher算法
- hihocoder1032(最长回文子串manacher算法)
- HDU3068(最长回文子串manacher算法)
- 最长回文子串 用manacher算法
- hiho1032 : 最长回文子串 Manacher算法
- 最长回文子串 - Manacher算法
- Android 上传图片至服务器
- PLSQL Developer用户登录时提示:ORA-28000: the account is locked
- AsyncTask、View.post(Runnable)、ViewTreeObserver三种方式总结frame animation自动启动
- C++中的this指针
- Linux软件的安装和卸载
- Manacher算法(最长子回文串)
- css抖动基础
- 整数换为字符串
- 用sqlite存储Android手机图片,再从数据库读出图片显示。
- JAVA同步(synchronized)
- 如何提高Service的优先级避免被杀死或者杀死后如何再次重启Service?
- Eclipse中EditText无法渲染的解决方法
- hdu 5190 Go to movies
- NEUQ 1276:老王赛马