hdu3294 manacher
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的更多相关文章
- hdu3294 manacher算法
这道题哇 其实是裸的manacher 无论怎么变 是回文的就是回文 所以 特殊处理一下输出就好了 不过最后的左右端点l,r.l=(p-p[pos]+2)/2-1,r=(p+p[pos]-2)/2-1; ...
- hdu3294 Manacher算法模板
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/3294/ 回文长度如果是mxx,回文中心是id的话,在扩展串中(id-mxx+1,id+mxx-1)的这段中去除标 ...
- HDU3294 Girls' research —— Manacher算法 输出解
题目链接:https://vjudge.net/problem/HDU-3294 Girls' research Time Limit: 3000/1000 MS (Java/Others) M ...
- hdu3294(manacher)
传送门:Girls' research 题意:求最长回文串并输出位置及转换后的字符串. 分析:manacher算法算出最长回文串后记录中心位置,然后再转换回原字符串的起始和结束位置. #pragma ...
- 【 HDU3294 】Girls' research (Manacher)
BUPT2017 wintertraining(15) #5F HDU - 3294 题意 给定字母x,字符串变换一下: 'x'-1 -> 'z', 'x'->'a', 'x'+1-> ...
- hdu3294 Girls' research manacher
One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...
- KMP 、扩展KMP、Manacher算法 总结
一. KMP 1 找字符串x是否存在于y串中,或者存在了几次 HDU1711 Number Sequence HDU1686 Oulipo HDU2087 剪花布条 2.求多个字符串的最长公共子串 P ...
- 马拉车manacher
目的:线性查找一个串的最长回文子串 时间复杂度:O(n) len[i]表示以i为中心的回文串的半径,mx即为当前计算回文串最右边字符的最大值,p是中心点mid,mx-i和2*p-1关于p对称 http ...
- HDU3068 回文串 Manacher算法
好久没有刷题了,虽然参加过ACM,但是始终没有融会贯通,没有学个彻底.我干啥都是半吊子,一瓶子不满半瓶子晃荡. 就连简单的Manacher算法我也没有刷过,常常为岁月蹉跎而感到后悔. 问题描述 给定一 ...
随机推荐
- Adobe Illustrator CS6 界面文字按钮太小,高分屏win10PS/AI等软件界面字太小解决方法
Adobe Illustrator CS6 界面文字按钮太小,高分屏win10PS/AI等软件界面字太小解决方法 Adobe App Scaling on High DPI Displays (FIX ...
- Linux中Postfix邮件发送配置(三)
部署DNS服务器 postfix根据域名和地址做一个MX记录,A记录,PTR记录(一般在互联网上邮件服务器都要反解,没有PTR记录会认为是垃圾邮件) $ service iptables stop $ ...
- python之路----包
包 包是一种通过使用‘.模块名’来组织python模块名称空间的方式. 1. 无论是import形式还是from...import形式,凡是在导入语句中(而不是在使用时)遇到带点的,都要第一时间提高警 ...
- Python3 matplotlib的绘图函数subplot()简介
Python3 matplotlib的绘图函数subplot()简介 一.简介 matplotlib下, 一个 Figure 对象可以包含多个子图(Axes), 可以使用 subplot() 快速绘制 ...
- 08: Django使用haystack借助Whoosh实现全文搜索功能
参考文章01:http://python.jobbole.com/86123/ 参考文章02: https://segmentfault.com/a/1190000010866019 参考官网自定制v ...
- ms11_050漏洞攻击
ms11_050漏洞攻击 开启msfconsole 查看针对MS11_050漏洞的攻击模块 进入模块 查看该模块的具体信息 设置paylaods 查看具体参数设置 设置其相关参数 攻击 ie浏览器发生 ...
- tf.placeholder使用说明
tf.placeholder(dtype, shape=None, name=None) placeholder,占位符,在tensorflow中类似于函数参数,运行时必须传入值. dtype:数据类 ...
- 字符编码之间的相互转换 UTF8与GBK(转载)
转载自http://www.cnblogs.com/azraelly/archive/2012/06/21/2558360.html UTF8与GBK字符编码之间的相互转换 C++ UTF8编码转换 ...
- git下载速度太慢【学习笔记】
使用了sshFQ的伙伴添加这个配置下载速度有极大的提升. git config --global http.proxy 'socks5://127.0.0.1:1080'
- 在ubuntu下随意编译安装需要的python版本
一.环境 ubuntu14.04 二.准备 2.1更新软件库 sudo apt-get update 2.2安装编译器及相应工具 2.3安装相应的开发库 sudo apt-get install zl ...