ZZULIOJ-1961 斗破苍穹(马拉车算法)
来源:互联网 发布:s2011网络设置 编辑:程序博客网 时间:2024/06/10 04:30
求最长回文串
#include <cstring>#include <cstdio>#include <algorithm>#include <iostream>#include <queue>#define maxn 100005using namespace std;char str[maxn], ch[maxn<<1];int len[maxn<<1];void Init(){ int j = 0; scanf("%s", str); ch[0] = '@'; for(int i = 0; str[i]; i++){ ch[++j] = '#'; ch[++j] = str[i]; } ch[++j] = '#'; ch[++j] = 0;}int Manacher(){ int mex = 0, id, ans = 0; for(int i = 1; ch[i]; i++){ if(mex > i) len[i] = min(len[2*id-i], mex-i); else len[i] = 1; while(ch[i+len[i]] == ch[i-len[i]]) len[i]++; if(i + len[i] > mex){ mex = i + len[i]; id = i; ans = max(ans, len[i]-1); } } return ans; }int main(){// freopen("in.txt", "r", stdin); int t; cin >> t; while(t--){ Init(); cout << Manacher() << endl; } return 0;}
0 0
- ZZULIOJ-1961 斗破苍穹(马拉车算法)
- 斗破苍穹
- 斗破苍穹RPG
- 斗破苍穹
- 4》斗破苍穹
- 1861: 斗破苍穹
- 斗破苍穹里的那些女人
- ZZULI 1861: 斗破苍穹【回文字符串】
- 马拉车算法
- 马拉车算法
- 马拉车算法
- 马拉车算法模板
- 1861: 斗破苍穹 【最长回文子串】
- HDU 3294 马拉车算法
- Manacher马拉车算法总结
- 最长回文 --马拉车算法
- 最长回文子串-----“马拉车”算法
- Manacher's Algorithm 马拉车算法
- wince中BIB文件的详细介绍
- Block的基本使用
- AS插件-Android Drawable Importer
- Linux开机启动,设置rc.local失效解决方案
- apache 2.2.15+tomcat6 集群
- ZZULIOJ-1961 斗破苍穹(马拉车算法)
- MFC——11.GDI 2D编程基础
- eclipse进行Android开发的环境搭建
- gradle入门
- Hive第一课配置安装
- MYSQL常用函数使用备忘录(更新中...)
- vpn访问国内外分流(支持windows、mac、linux)
- 泛型
- App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Te