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. 【转】svn http://提示svn: Unrecognized URL scheme错误

    转自:http://blog.csdn.net/l241002209/article/details/8547943 SVN这个东西虽然不好用(当然也是因为自身没有重视,但是谁让GIT这么好用呢…!) ...

  2. Java系列笔记(5) - 线程

    我想关注这个系列博客的粉丝们都应该已经发现了,我一定是个懒虫,在这里向大家道歉了.这个系列的博客是在我工作之余写的,经常几天才写一小节,不过本着宁缺毋滥的精神,所有写的东西都是比较精炼的.这篇文章是本 ...

  3. Python Web学习笔记之WebSocket原理说明

    众所周知,Web应用的通信过程通常是客户端通过浏览器发出一个请求,服务器端接收请求后进行处理并返回结果给客户端,客户端浏览器将信息呈现.这种机制对于信息变化不是特别频繁的应用可以良好支撑,但对于实时要 ...

  4. php检查是否是数字和字母

    /* 检查是否是数字和字母* php内置函数ctype_alnum检查字符串是否是数字和字母,或者两者混合* $string*/ public function is_numandlitter($st ...

  5. Python3 pip出现Fatal error in launcher: Unable to create process using '"'

    Python3 pip出现Fatal error in launcher: Unable to create process using '"' 问题分析: 先python2又安装了pyth ...

  6. MemcacheQ安装

    一.memcacheq介绍 特性: 1.简单易用 2.处理速度快 3.多条队列 4.并发性能好 5.与memcache的协议兼容 6.在zend framework中使用方便 memcacheq依赖于 ...

  7. 20145304 Exp6 信息搜集与漏洞扫描

    20145304 Exp6 信息搜集与漏洞扫描 实验后回答问题 (1)哪些组织负责DNS,IP的管理. NSI负责Internet顶级域名系统的注册.协调与维护,IAIA负责Internet的地址资源 ...

  8. Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案

    Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...

  9. USB Compound Device,USB复合设备 ; USB Composite Device,USB组合设备【转】

    本文转载自:https://blog.csdn.net/autumn20080101/article/details/52776863 科普下USB复合设备和USB组合设备的区别. 关键字 Commu ...

  10. 自定义redis序列化工具

    redis一个优点就是可以将数据写入到磁盘中. 我们知道写入磁盘的数据实际上都是以字节(0101这样的二进制数据)的形式写入的. 这意味着如果我们要将一个对象写入磁盘,就必须将这个对象序列化. jav ...