马拉车算法——求回文串起点hdu3294
#include<bits/stdc++.h>
using namespace std;
#define maxn 500005
int p[maxn];
char s[maxn],s_new[maxn],ch[];
int start;
int init(){
int len=strlen(s);
int j=;
s_new[]='$',s_new[]='#';
for(int i=;i<len;i++){
s_new[j++]=s[i];
s_new[j++]='#';
}
s_new[j]=;
return j;
}
int manacher(){
int len=init();
int mx=,id,res=;
start=;
for(int i=;i<len;i++){
if(mx>i)p[i]=min(p[id*-i],mx-i);
else p[i]=;
while(s_new[i-p[i]]==s_new[i+p[i]])p[i]++;
if(mx<i+p[i])
mx=i+p[i],id=i;
if(res<p[i]-)
res=p[i]-,start=(i-p[i]+)/-;
}
return res;
}
int main(){
while(scanf("%s%s",ch,s)!=EOF){
memset(p,,sizeof p);
int res=manacher();
if(res<=){
puts("No solution!");
continue;
}
cout<<start<<" "<<start+res-<<'\n';
for(int i=start;i<start+res;i++){
if(s[i]-ch[]>=)cout<<(char)(s[i]-ch[]+'a');
else cout<<(char)(s[i]-ch[]++'a');
}
puts("");
}
}
马拉车算法——求回文串起点hdu3294的更多相关文章
- HDU 5371(2015多校7)-Hotaru's problem(Manacher算法求回文串)
题目地址:HDU 5371 题意:给你一个具有n个元素的整数序列,问你是否存在这样一个子序列.该子序列分为三部分,第一部分与第三部分同样,第一部分与第二部分对称.假设存在求最长的符合这样的条件的序列. ...
- 马拉车算法——求回文子串个数zoj4110
zoj的测评姬好能卡时间.. 求回文子串的个数:只要把p[i]/2就行了: 如果s_new[i]是‘#’,算的是没有中心的偶回文串 反之是奇回文串 /* 给定两个字符串s,t 结论:s,t不相同的第一 ...
- SPOJ STC02 - Antisymmetry(Manacher算法求回文串数)
http://www.spoj.com/problems/STC02/en/ 题意:给出一个长度为n的字符串,问其中有多少个子串s可以使得s = s按位取反+翻转. 例如样例:11001011. 10 ...
- 马拉车,O(n)求回文串
马拉车,O(n)求回文串 对整个马拉车算法步骤做个总结: 第一步:将每个原字母用两个特殊字符包围如: aaa --> #a#a#a# abab -->#a#b#a#b 同时可以由这个翻倍的 ...
- Palindrome - URAL - 1297(求回文串)
题目大意:RT 分析:后缀数组求回文串,不得不说确实比较麻烦,尤其是再用线段数进行查询,需要注意的细节地方比较多,比赛实用性不高......不过练练手还是可以的. 线段数+后缀数组代码如下: ...
- 2021.12.10 P5041 [HAOI2009]求回文串(树状数组求逆序对)
2021.12.10 P5041 [HAOI2009]求回文串(树状数组求逆序对) https://www.luogu.com.cn/problem/P5041 题意: 给一个字符串 \(S\) ,每 ...
- manacher算法,求回文串
用来求字符串最长回文串或者回文串的总数量 #include<map> #include<queue> #include<stack> #include<cma ...
- LOJ 2452 对称 Antisymmetry——用hash求回文串数
概念 用hash求最长回文串/回文串数 首先,易知,回文串具有单调性. 如果字符串 $s[l...r]$ 为回文串串,那么 $s[x...y]$($l < x, y < r$ 且 $|l- ...
- hdu 3294 manacher 求回文串
感谢: http://blog.csdn.net/ggggiqnypgjg/article/details/6645824/ O(n)求给定字符串的以每个位置为中心的回文串长度. 中心思想:每次计算位 ...
随机推荐
- nginx springboot配置
1.下载安装nginx 2.nginx.conf文件修改参数 上方是代理后的端口,代理的server.下方是需要代理的路径 3.windows 下操作指令 启动 直接点击Nginx目录下的nginx. ...
- Linux下的Locale详解
locale这个单词中文翻译成地区或者地域,其实这个单词包含的意义要宽泛很多.Locale是根据计算机用户所使用的语言,所在国家或者地区,以及当地的文化传统所定义的一个软件运行时的语言环境. loca ...
- [Windows Doc]微软官方文档
desktop: https://docs.microsoft.com/en-us/windows/desktop/index server:https://docs.microsoft.com/en ...
- 将CSV文件存为HTML文件形式
# -*- coding: utf-8 -*- """ Created on Mon Apr 29 09:24:04 2019 @author: history &quo ...
- python全栈开发中级班全程笔记(第二模块、第四章)(常用模块导入)
python全栈开发笔记第二模块 第四章 :常用模块(第二部分) 一.os 模块的 详解 1.os.getcwd() :得到当前工作目录,即当前python解释器所在目录路径 impor ...
- python11 函数的定义,调用,分类
## 复习 #一.什么是函数:具体特定功能的代码块 - 特定功能代码块作为一个整体,并给该整体命名,就是函数 # 二.函数的优点:# 1.减少代码的冗余# 2.结构清晰,可读性强# 3.具有复用性,开 ...
- Python高级笔记(四) -- 多继承_方法解析顺序表MRO
1. 多继承以及MRO顺序 1.1 单独调用父类的方法 # -*- encoding=utf-8 -*- class Parent(object): def __init__(self, name): ...
- 为程序启用 守护进程-- supervisior
待补充... Add this to your /etc/supervisord.conf: [rpcinterface:supervisor] supervisor.rpcinterface_fac ...
- NIPS2017-The neural hawks process
NIPS2017哪些论文值得关注 论文链接 1.首先这篇文章研究的是 event stream,什么是event stream呢 ? 假如你是一个医生,你每天会看到很多病人 ,对于每一个病人,你都有他 ...
- CDH5.16.1的maven依赖版本查询地址
1查询官网地址,提供了详细的各个版本的jar依赖版本信息 https://www.cloudera.com/documentation/enterprise/release-notes/topics/ ...