hdu3068 Manacher --> find the longest palindrome
2016-08-12 22:12
330 查看
#include<bits/stdc++.h> using namespace std; char ss[250020]; char s[250020]; int p[250000]; int main(){ while(scanf("%s",s)!=EOF){ memset(p,0,sizeof(p)); int i,j; int len = 0; ss[len++] = '$'; int ll = strlen(s); for(i=0;i<ll;i++){ ss[len++] = '#'; ss[len++] = s[i]; } int mx = 0; int id = 0; ss[len++] = '#'; ss[len] = '\0'; for(i=1;i<len;i++){ if(i<mx){ p[i] = min(mx-i,p[2*id-i]); }else{ p[i] = 1; } while(ss[i+p[i]]==ss[i-p[i]]){ p[i]++; } if(i+p[i]>mx){ mx = p[i]+i; id = i; } } cout<<*max_element(p,p+len)-1<<endl; } return 0; }
相关文章推荐
- HDU1595 find the longest of the shortest[最短路]
- HDU 1595 find the longest of the shortest
- HDU 1595 find the longest of the shortest
- <综合>java virtual machine launcher 提示 could not find the main class,program will exit 问题
- find the longest of the shortest
- Problem 14 - Find the longest sequence using a starting number under one million.
- find the longest of the shortest --spfa删边
- HDU 1595——find the longest of the shortest
- HDU 1595 find the longest of the shortest
- Write a function to find the longest common common string amongst an array of strings.
- 解决“could not find gem 'turn <>=0 ' in any of the gem sources listed in your gemfile”错误
- Struts2---->Cannot find the tag library descriptor for /struts-tags
- HDOJ 1595 find the longest of the shortest (枚举最短路+删除)
- hdu 1595 find the longest of the shortest(最短路spfa)
- HDU 1595 find the longest of the shortest(枚举,最短路)
- JOJ2519 Find the longest section(位运算 +(前缀和?))
- Given a string S, find the longest palindromic substring in S.
- 1595 hdu find the longest of the shortest
- 最长回文子串(Longest Palindrome Substring)--Manacher算法O(n)
- HDU 1595 find the longest of the shortest【次短路】