Girls' research(manacher)
Girls' research
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1160 Accepted Submission(s): 448
题解:用manacher保存位置;然后再转义字符;
输入一个字符ch和一个字符串,问如果把ch当作'a'的话,字符串的每个字符也要做相应变化,如b aa,若b为'a',则b前面的a就为'a'前面的'z',这里是循环表示,输出字符串的最长回文子串,如果最长回文子串串长为1,输出No solution!
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long LL;
const int MAXN=200010;
char s[MAXN],a[MAXN<<1];
int ans,ps;
int p[MAXN<<1];
void manacher(){
int m=1,l=1,r=1;
ans=0;ps=0;
int len=strlen(a);
p[0]=p[1]=1;
for(int i=2;i<len;i++){
if(r>i)p[i]=min(p[m-(i-m)],r-i);
else p[i]=1;
while(a[i-p[i]]==a[i+p[i]])p[i]++;
if(p[i]+i>r)r=p[i]+i,m=i;
if(p[i]-1>ans)ans=p[i]-1,ps=i;
}
}
int main(){
char ch[2];
while(~scanf("%s%s",ch,s)){
int len=strlen(s);
a[0]='#';
for(int i=0;i<len;i++){
a[i*2+1]=s[i];
a[i*2+2]='#';
}
a[len*2+1]='#';a[len*2+2]='\0';
manacher();
//printf("%d\n",ans);
int l=(ps-ans+1)/2,r=l+ans-1;
if(ans==1){
puts("No solution!");continue;
}
printf("%d %d\n",l,r);
int t=ch[0]-'a';
for(int i=l;i<=r;i++){
if(s[i]-'a'>=t)printf("%c",s[i]-t);
else printf("%c",s[i]-t+26);
}puts("");
}
return 0;
}
Girls' research(manacher)的更多相关文章
- HDU3294 Girls' research —— Manacher算法 输出解
题目链接:https://vjudge.net/problem/HDU-3294 Girls' research Time Limit: 3000/1000 MS (Java/Others) M ...
- Hdu 3294 Girls' research (manacher 最长回文串)
题目链接: Hdu 3294 Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.... ...
- hdu 3294 Girls' research(manacher)
Problem Description One day, sailormoon girls are so delighted that they intend to research about pa ...
- hdu3294 Girls' research manacher
One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...
- 【 HDU3294 】Girls' research (Manacher)
BUPT2017 wintertraining(15) #5F HDU - 3294 题意 给定字母x,字符串变换一下: 'x'-1 -> 'z', 'x'->'a', 'x'+1-> ...
- HDU----(3294)Girls' research(manacher)
Girls' research Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)T ...
- (回文串 Manacher )Girls' research -- hdu -- 3294
http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit:1000MS Memory Limit:32 ...
- HDU 3294 Girls' research(manachar模板题)
Girls' researchTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- HDU 3294 (Manacher) Girls' research
变形的求最大回文子串,要求输出两个端点. 我觉得把'b'定义为真正的'a'是件很无聊的事,因为这并不会影响到最大回文子串的长度和位置,只是在输出的时候设置了一些不必要的障碍. 另外要注意一下原字符串s ...
随机推荐
- C# 对象拷贝问题 =等同于浅拷贝
大家都知道,在C#中变量的存储分为值类型和引用类型两种,而值类型和引用类型在数值变化是产生的后果是不一样的,值类型我们可以轻松实现数值的拷贝,那么引用类型呢,在对象拷贝上存在着一定的难度. 下 ...
- VS2013 RC 此模板尝试加载组件程序集 “NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral.........
微软发布了vs2013的RC版本,更新了自己机器上的vs,在创建项目过程中,发现出现如题的相关错误,查了相关msdn的资料,才了解到vs已经全面切换到使用NuGet这个第三方开源工具来管理项目包和引用 ...
- 浅谈Struts2(一)
一.Struts2引言 1.Struts2框架的概念 解决的MVC开发过程中,控制器(Controller)的通用问题. a.什么是MVC开发 MVC开发是一种编程思想,由设计者人为的把一个项目,划分 ...
- UVa202 Repeating Decimals
#include <stdio.h>#include <map>using namespace std; int main(){ int a, b, c, q, r, p ...
- libuv 错误号UV_ECANCELED 的处理
这个地方有好多的不明白,也没仔细的看懂代码,希望有牛人指点. 先记录几个issue 1. after_write recv many(>10000) ECANCELED in my write_ ...
- xcode6编译cocos2dx项目出现Undefined symbols _fwrite$UNIX2003
当xcode6编译cocos2dx的时候会出现Undefined symbols _fwrite$UNIX2003 这个问题.google了一篇文章:http://stackoverflow.com/ ...
- Latex调整行距
修改行间距的方法: \usepackage{setspace}%使用间距宏包 \begin{document} \begin{spacing}{2.0}%%行间距变为double-space 双倍行距 ...
- include file和include virtual的区别
1.#include file 包含文件的相对路径,#include virtual包含文件的虚拟路径. 2.在同一个虚拟目录内,<!--#include file="file.asp ...
- js函数调用模式总结
在javascript中一共有四种调用模式:方法调用模式.函数调用模式.构造器调用模式和apply调用模式.这些模式在如何初始化关键参数this上存在差异 方法调用模式 当一个函数被保存为对象的一个属 ...
- HDU 3466 Proud Merchants
题目大意:现在给出商品,有三个参数,记为pi,qi,vi,vi是商品的在你心里价值,pi是商品的价格,qi是你要买商品的时候至少需要的钱然后求可得的最大价值. 单词积累:Merchants 商人 t ...