Girls' research

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1160    Accepted Submission(s): 448

Problem Description
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.
 
Input
Input 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.
 
Output
Please 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!
 

题解:用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)的更多相关文章

  1. HDU3294 Girls' research —— Manacher算法 输出解

    题目链接:https://vjudge.net/problem/HDU-3294 Girls' research Time Limit: 3000/1000 MS (Java/Others)    M ...

  2. Hdu 3294 Girls' research (manacher 最长回文串)

    题目链接: Hdu 3294  Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.... ...

  3. hdu 3294 Girls' research(manacher)

    Problem Description One day, sailormoon girls are so delighted that they intend to research about pa ...

  4. hdu3294 Girls' research manacher

    One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...

  5. 【 HDU3294 】Girls' research (Manacher)

    BUPT2017 wintertraining(15) #5F HDU - 3294 题意 给定字母x,字符串变换一下: 'x'-1 -> 'z', 'x'->'a', 'x'+1-> ...

  6. HDU----(3294)Girls' research(manacher)

    Girls' research Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)T ...

  7. (回文串 Manacher )Girls' research -- hdu -- 3294

    http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit:1000MS     Memory Limit:32 ...

  8. HDU 3294 Girls' research(manachar模板题)

    Girls' researchTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...

  9. HDU 3294 (Manacher) Girls' research

    变形的求最大回文子串,要求输出两个端点. 我觉得把'b'定义为真正的'a'是件很无聊的事,因为这并不会影响到最大回文子串的长度和位置,只是在输出的时候设置了一些不必要的障碍. 另外要注意一下原字符串s ...

随机推荐

  1. SQL Server 链接数据库 error:40

    链接到远程服务器的话,经常犯这个错误,所以做个笔记,省的每次去百度. 1.如果使用的是 local 链接,只需要启动服务就可以了(如下图) 2.如果是远程链接的话,那么是需要启动TCP协议的,步骤如下

  2. c 跟字符串有关的函数

    1.字符串查找 strstr char * strstr(const char *s1, const char *s2); 在s1中查找s2,如果找到返回首个s2的首地址 char * strcase ...

  3. Android四大组件之Activity详解

    一.Activity的概要说明 我看过Activity的源码,Activity类注释大概是这样解释的:几乎所有的Activity都是与用户交互用的,我想用了一个几乎的意思应该是排除一些纯展示界面吧,因 ...

  4. js函数变量

    局部 JavaScript 变量 在 JavaScript 函数内部声明的变量(使用 var)是局部变量,所以只能在函数内部访问它.(该变量的作用域是局部的). 您可以在不同的函数中使用名称相同的局部 ...

  5. zoj 3195 Design the city lca倍增

    题目链接 给一棵树, m个询问, 每个询问给出3个点, 求这三个点之间的最短距离. 其实就是两两之间的最短距离加起来除2. 倍增的lca模板 #include <iostream> #in ...

  6. 安装 Rational Rose 启动报错:无法启动此程序,因为计算机中丢失 suite objects.dll

    安装完以后提示找不到 suite objects.dll: 经查找,该 dll 存在: 找不到的原因是,安装程序自动设置在 Path 中的环境变量有误: 把最后的 common 改成 Common: ...

  7. Inlay技术要求

    物理特性: 项目 要求内容 备考 基准值 公差 INLAY尺寸 A(长) 480mm ±0.5mm B(宽) 380mm ±0.5mm 线圈位置 C(天地位置) 16.05mm ±0.2mm D(左右 ...

  8. 二代USBKEY与一代USBKEY有什么区别?使用时需要注意什么?

    二代USBKEY相较于一代USBKEY产品,增加了屏幕以及按键功能:可通过二代USBKEY产品的屏幕查看交易或操作信息,通过按键的方式进行上翻.下翻.确认.取消等操作. 二代USBKEY产品采用Mic ...

  9. python的正则表达式 re

    python的正则表达式 re 本模块提供了和Perl里的正则表达式类似的功能,不关是正则表达式本身还是被搜索的字符串,都可以是Unicode字符,这点不用担心,python会处理地和Ascii字符一 ...

  10. hdoj 3018 Ant Trip(无向图欧拉路||一笔画+并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3018 思路分析:题目可以看做一笔画问题,求最少画多少笔可以把所有的边画一次并且只画一次: 首先可以求出 ...