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. tomcat警告WARNING: An attempt was made to authenticate the locked user "user"

    后台出现很多警告WARNING: An attempt was made to authenticate the locked user "user"Jul 19, 2017 2: ...

  2. fastDFS errcode:9 path:Bad file descriptor errcode:22 path:Invalid argument

    fastDFS errcode:9 path:Bad file descriptor errcode:22 path:Invalid argument <error>status:4 er ...

  3. Oracle 11g调用函数几种常用方法

    1. 该函数接受3个可选参数,返回3个数字的和 CREATE OR REPLACE FUNCTION add_three_numbers ( a NUMBER:=0, b NUMBER:=0, c N ...

  4. 保护Hadoop集群三大方法

    自今年以来,不少恶意软件开始频繁向Hadoop集群服务器下手,受影响最大的莫过于连接到互联网且没有启用安全防护的Hadoop集群. 大约在两年前,开源数据库解决方案MongoDB以及Hadoop曾遭受 ...

  5. python之路----面向对象的多态特性

    多态 多态指的是一类事物有多种形态 动物有多种形态:人,狗,猪 import abc class Animal(metaclass=abc.ABCMeta): #同一类事物:动物 @abc.abstr ...

  6. Putty Technical Note

    转载自:http://libai.math.ncu.edu.tw/bcc16/6/putty/puttyt.html Terminal panel Terminal 面板可調整 PuTTY 對於模擬終 ...

  7. SNMP学习笔记之iReasoning MIB Browser

    0x00 MIB Browser iReasoning MIB浏览器是一个强大和易于使用的工具由iReasoning SNMP API提供支持. MIB浏览器是工程师管理启用SNMP的网络设备和应用程 ...

  8. Removing bad blocks from the USB drive with fsck

    An easy way to repair a flash drive, or any drive really, is to use the fsck tool. This tool is grea ...

  9. log4j 根据类名指定文件

    log4j.logger.io.netty=INFO, stdout, spiderlog4j.logger.com.ld.net.spider=INFO, stdout, spider log4j. ...

  10. 使用 Vue.js 结合bootstrap 实现的分页控件

    原文链接:http://blog.csdn.net/qiuhaotc/article/details/53031884 源码下载: http://pan.baidu.com/s/1i4XgH6H 密码 ...