One day, sailormoon girls are so delighted that they intend to research about palindromic strings. Operation contains two steps: 
First step: girls will write a long string (only contains lower case) on the paper. For example, "abcde", but 'a' inside is not the real 'a', that means if we define the 'b' is the real 'a', then we can infer that 'c' is the real 'b', 'd' is the real 'c' ……, 'a' is the real 'z'. According to this, string "abcde" changes to "bcdef".
Second step: girls will find out the longest palindromic string in the given string, the length of palindromic string must be equal or more than 2.

InputInput contains multiple cases. 
Each case contains two parts, a character and a string, they are separated by one space, the character representing the real 'a' is and the length of the string will not exceed 200000.All input must be lowercase. 
If the length of string is len, it is marked from 0 to len-1.OutputPlease execute the operation following the two steps. 
If you find one, output the start position and end position of palindromic string in a line, next line output the real palindromic string, or output "No solution!". 
If there are several answers available, please choose the string which first appears.Sample Input

b babd
a abcd

Sample Output

0 2
aza
No solution!
题意:求改变后的字符串的最长回文
题解:先用map预处理再套一个manacher就行了
(刚开始居然又是tle搞得我很忧伤啊,以为写搓了,改了好几遍终于发现用全局变量就能ac了(不过这是个什么鬼原理))
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 10007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=(<<)-,inf=0x3f3f3f3f; int p[N],slen;
string str;
void manacher()
{
int mx=,id;
for(int i=;i<slen;i++)
{
if(mx>i)p[i]=min(p[*id-i],mx-i);
else p[i]=;
while(str[i+p[i]]==str[i-p[i]])p[i]++;
if(i+p[i]>mx)
{
mx=i+p[i];
id=i;
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
// cout<<setiosflags(ios::fixed)<<setprecision(2);
char op;
string s;
while(cin>>op>>s){
map<char,char>m;
char k='a';
for(int i=;i<;i++)
{
if(op>'z')op-=;
m[op++]=k++;
}
for(int i=;i<s.size();i++)s[i]=m[s[i]];
str="$#";
for(int i=;i<s.size();i++)
{
str+=s[i];
str+="#";
}
// cout<<str<<endl;
slen=str.size();
memset(p,,sizeof p);
manacher();
int ans=-,index;
for(int i=;i<str.size();i++)
if(ans<p[i]-)
{
ans=p[i]-;
index=(i-p[i])/;
}
if(ans>=)cout<<index<<" "<<index+ans-<<endl<<s.substr(index,ans)<<endl;
else cout<<"No solution!"<<endl;
}
return ;
}

hdu3294 manacher的更多相关文章

  1. hdu3294 manacher算法

    这道题哇 其实是裸的manacher 无论怎么变 是回文的就是回文 所以 特殊处理一下输出就好了 不过最后的左右端点l,r.l=(p-p[pos]+2)/2-1,r=(p+p[pos]-2)/2-1; ...

  2. hdu3294 Manacher算法模板

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/3294/ 回文长度如果是mxx,回文中心是id的话,在扩展串中(id-mxx+1,id+mxx-1)的这段中去除标 ...

  3. HDU3294 Girls' research —— Manacher算法 输出解

    题目链接:https://vjudge.net/problem/HDU-3294 Girls' research Time Limit: 3000/1000 MS (Java/Others)    M ...

  4. hdu3294(manacher)

    传送门:Girls' research 题意:求最长回文串并输出位置及转换后的字符串. 分析:manacher算法算出最长回文串后记录中心位置,然后再转换回原字符串的起始和结束位置. #pragma ...

  5. 【 HDU3294 】Girls' research (Manacher)

    BUPT2017 wintertraining(15) #5F HDU - 3294 题意 给定字母x,字符串变换一下: 'x'-1 -> 'z', 'x'->'a', 'x'+1-> ...

  6. hdu3294 Girls' research manacher

    One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...

  7. KMP 、扩展KMP、Manacher算法 总结

    一. KMP 1 找字符串x是否存在于y串中,或者存在了几次 HDU1711 Number Sequence HDU1686 Oulipo HDU2087 剪花布条 2.求多个字符串的最长公共子串 P ...

  8. 马拉车manacher

    目的:线性查找一个串的最长回文子串 时间复杂度:O(n) len[i]表示以i为中心的回文串的半径,mx即为当前计算回文串最右边字符的最大值,p是中心点mid,mx-i和2*p-1关于p对称 http ...

  9. HDU3068 回文串 Manacher算法

    好久没有刷题了,虽然参加过ACM,但是始终没有融会贯通,没有学个彻底.我干啥都是半吊子,一瓶子不满半瓶子晃荡. 就连简单的Manacher算法我也没有刷过,常常为岁月蹉跎而感到后悔. 问题描述 给定一 ...

随机推荐

  1. python 类的私有方法例子

    #coding=utf-8 class Person(object):    id=12    def __init__(self,name):        self.name=name       ...

  2. linux下如何进入单用户模式

    忘记密码时,我们可以通过进入单用户模式修改密码. 进入单用户模式的方式: 1. 启动服务器时,按 e 键进入引导选择界面.注意:可能需要多次按 e 键切换几个个界面后,才能进入选择界面. 2. 选择以 ...

  3. Linux基础命令---chown

    chown 改变文件或者目录的所有者,或者所属的群组.如果只给出一个所有者(用户名或数字用户ID),则该用户将成为每个给定文件的所有者,并且文件的组不会被更改.如果所有者后面跟着冒号和组名(或数字组I ...

  4. Python入门之字典的操作详解

    这篇文章主要介绍了Python 字典(Dictionary)的详细操作方法,需要的朋友可以参考下: Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串.数字.元组等其他容器模型. 一 ...

  5. 作为从业人员,如果一定要学一门新的编程语言,那么它一定是c++

    作为从业人员,如果一定要学一门新的编程语言,那么它一定是c++. 无论各种编程语言排行榜如何变化,什么语言最赚钱,想成为真正的程序员,那么c/c++是必修课,因为几乎所有的底层都是c/c++编写的,各 ...

  6. 04: 打开tornado源码剖析处理过程

    目录:Tornado其他篇 01: tornado基础篇 02: tornado进阶篇 03: 自定义异步非阻塞tornado框架 04: 打开tornado源码剖析处理过程 目录: 1.1 torn ...

  7. 任务调度之Timer与TimerTask配合

    什么是任务调度? 在实际业务中,我们经常需要定时.定期.或者多次完成某些任务,对这些任务进行管理,就是任务调度.任务调度与多线程密切相关. 任务调度有多种方式 Timer与TimerTask配合 Ti ...

  8. VC++ 进度条更新方案

    在实际开发中,如果有耗时操作,一般会在工作线程处理数据,然后处理完成后把时间传递到UI线程进行显示,切记不要在工作线程对UI进行操作. 场景: 1. 很多程序需要根据处理业务的进度来更新进度条,进度条 ...

  9. Linux内核同步机制--自旋锁【转】

    本文转载自:http://www.cppblog.com/aaxron/archive/2013/04/12/199386.html 自旋锁与互斥锁有点类似,只是自旋锁不会引起调用者睡眠,如果自旋锁已 ...

  10. acm模板生成

    为迎接,接下来的区域赛,要做好准备(虽然不是特别有信心,但是还是要鼓励自己,可以取得收获的,加油) acm_latex模板: https://www.cnblogs.com/palayutm/p/64 ...