hdu3294(manacher)
传送门:Girls' research
题意:求最长回文串并输出位置及转换后的字符串。
分析:manacher算法算出最长回文串后记录中心位置,然后再转换回原字符串的起始和结束位置。
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-6
#define N 200010
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PII pair<int,int>
using namespace std;
inline LL read()
{
char ch=getchar();LL x=,f=;
while(ch>''||ch<''){if(ch=='-')f=-;ch=getchar();}
while(ch<=''&&ch>=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int p[N<<],ans,len,num,mx,id,pos;
char s[N],str[N<<],ch[];
void build()
{
len=strlen(s);num=;
str[num++]='@';str[num++]='#';
for(int i=;i<len;i++)
{
str[num++]=s[i];
str[num++]='#';
}
str[num]=;
}
void manacher()
{
ans=;mx=;
memset(p,,sizeof(p));
for(int i=;i<num;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(p[i]+i>mx)mx=p[i]+i,id=i;
if(ans<p[i]-)ans=p[i]-,pos=i;
}
}
char charge(char c)
{
return (c-ch[]+)%+'a';
}
int main()
{
while(scanf("%s%s",ch,s)>)
{
build();
manacher();
if(ans<)puts("No solution!");
else
{
int a,b;
if(pos%)
{
a=pos/-ans/;
b=a+ans-;
}
else
{
a=pos/-ans/-;
b=a+ans-;
}
printf("%d %d\n",a,b);
for(int i=a;i<=b;i++)printf("%c",charge(s[i]));
puts("");
}
}
}
hdu3294(manacher)的更多相关文章
- O(n)回文子串(Manacher)算法
O(n)回文子串(Manacher)算法 资料来源网络 参见:http://www.felix021.com/blog/read.php?2040 问题描述: 输入一个字符串,求出其中最大的回文子串. ...
- 【学习笔记】字符串—马拉车(Manacher)
[学习笔记]字符串-马拉车(Manacher) 一:[前言] 马拉车用于求解连续回文子串问题,效率极高. 其核心思想与 \(kmp\) 类似:继承. --引自 \(yyx\) 学姐 二:[算法原理] ...
- HDU 4513 吉哥系列故事——完美队形II(Manacher)
Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成 ...
- 牛客小白月赛13 小A的回文串(Manacher)
链接:https://ac.nowcoder.com/acm/contest/549/B来源:牛客网 题目描述 小A非常喜欢回文串,当然我们都知道回文串这种情况是非常特殊的.所以小A只想知道给定的一个 ...
- 2018.06.30 BZOJ 2342: [Shoi2011]双倍回文(manacher)
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符串 ...
- HDU----(3294)Girls' research(manacher)
Girls' research Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)T ...
- 最长回文(Manacher)
HOT~ 杭电2015级新生如何加入ACM集训队? 最长回文 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- CC 3-Palindromes(manacher)
传送门:3-Palindromes 题意:求为回文串且能整除3且不前导0的子串个数. 分析:由 manacher算法O(N)可算出以i为坐标的最长为p[i]回文子串,且Si-k,Si-k+1..... ...
- HDU - 3068 最长回文(manacher)
HDU - 3068 最长回文 Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Subm ...
随机推荐
- 基于visual Studio2013解决面试题之1109全排列
题目
- Research notes for Scientific Writing
Noun. complacency n. 自得;自鸣得意 nomenclature n. 专业术语:e.g. the nomenclature of music; 音乐的专门术语 Verb. abs ...
- linux命令:find
先上例子: find ./*_src -type f | xargs grep -ils "date" 在指定的那些文件夹下面,递归寻找包含“date” 字符串的普通文件. fin ...
- 基于visual Studio2013解决C语言竞赛题之1089牛虎过河
题目 解决代码及点评 /************************************************************************/ /* ...
- FindLetter 类——查找文件中特定的字符,每一行开头为某一个字符,则跳过
/*统计除了>之外的行里面CHED四个字母总数*/ #include<fstream> #include<iostream> #include<cstring> ...
- 基于特定值来推断隐藏显示元素的jQuery插件
jQuery-Visibly是一款小巧简单的jQuery隐藏显示元素插件.该插件依据某个元素的值,例如以下拉框的值.输入框的值等来推断是否显示某个指定的元素. 用于推断的值能够是单个值,或者是多个值, ...
- Extract Datasets
*&---------------------------------------------------------------------* *& Report ZTEST2013 ...
- java学习之路----内存的分析
java内存分析 在java中,java语言对程序员做了一个美好的承诺,就是程序员无需去管理内存,因为有GC,其实不然; 1.垃圾回收并不 ...
- C#实现环形队列
概述 看了一个数据结构的教程,是用C++写的,可自己C#还是一个菜鸟,更别说C++了,但还是大胆尝试用C#将其中的环形队列的实现写出来,先上代码: public class MyQueue<T& ...
- ubuntu安装iscsi
ubuntu安装iscsi target端:apt-get install iscsitarget ubuntu安装iscsi initiator端:apt-get install open-iscs ...