**链接:****传送门 **

思路:Manacher模板题,寻找串中的最长回文子串


/*************************************************************************
> File Name: hdu3068.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月19日 星期五 13时09分43秒
************************************************************************/ #include<bits/stdc++.h>
using namespace std; const int MAX_N = 110000*3;
char s[MAX_N] , str[MAX_N];
int len1 , len2 , p[MAX_N] , ans; // 对字符串进行预处理
void init(){
len1 = strlen(s);
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 , mx = 0;
for(int i = 1 ; i < len2 ; i++){
if( mx > i ) p[i] = min( p[2*id-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(){
while(~scanf("%s",s)){
init();
Manacher();
ans = 0;
for(int i = 1 ; i < len2 ; i++){
ans = max( ans , p[i] );
}
printf("%d\n",ans-1);
}
return 0;
}

最新文章

  1. Hadoop3 在eclipse中访问hadoop并运行WordCount实例
  2. MVC学习系列12---验证系列之Fluent Validation
  3. [日常训练]常州集训day2
  4. PHP中为位运算符(几乎很少用)
  5. 初识onselectstart
  6. Hark的数据结构与算法练习之多路归并排序
  7. UWP源码——Unit Test
  8. pcDuino 刷系统-卡刷
  9. Eclipse代理设置
  10. libev学习笔记
  11. 解决CentOS 7中php-fpm进程数过多导致服务器内存资源消耗较大的问题
  12. 资产信息之收集资产代码流程,API的一个认证,数据库表的设计
  13. 06_mysql先分页查询再排序
  14. 导弹拦截问题(DP+贪心)
  15. Scala - Tips
  16. UnsupportedClassVersionError: org/apache/maven/plugin/compiler/CompilerMojo : Unsupported major.minor version 51.0
  17. 支持flash in Chrome 2017
  18. golang配置
  19. [转载]JDBC/Spring/MyBatis性能比较
  20. java基础篇---I/O技术(二)

热门文章

  1. 3.2、Ansible单命令测试
  2. CentOS6.8安装
  3. vue-cli快速搭建
  4. HDU——T1231 最大连续子序列
  5. tomcat work目录的作用就是编译每个项目里的jsp文件为java文件如果项目没有jsp页面则这个项目文件夹为空
  6. crm使用soap批量删除数据
  7. NAT&amp;amp;Port Forwarding&amp;amp;Port Triggering
  8. servletConfig和ServletContext 以及servletContextListener介绍
  9. Gradle:Gradle入门
  10. java1.8对集合中对象的特有属性进行排序