Girls' research
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 4401 Accepted Submission(s): 1642

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!

题意:通过第一个字符与a的关系翻译字符串,输出最长回文串和首尾下标,不存在则输出No solution!

分析:用manachar求出最长回文串中心和半径,因为变换后的串各字符下标改变了,所以输出原首尾下标要公式倒推

输出字符时要跳过插入的符号

0   1   2   3   4   5   6   7   8   9 

$   *    b   *   a   *    b   *   d   *

#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
char s[400001];
int p[400001];//半径
int main()
{
char c;
while (~scanf("%s%s", &c, s))
{
int len = strlen(s);
for (int i = len; i >= 0; i--)
s[2 * i + 2] = s[i],
s[2 * i + 1] = '*';
s[0] = '$';
int r = 0, mid = 0;//最大半径及对应回文串中心
int id = 0, mx = 0;//半径延申到最右字符时的点和当时遍历到的最右字符的下标
for (int i = 1; i < len * 2 + 1; i++)
{
if ( i < mx)//小于最右点
p[i] = min(p[2 * id - i], mx - i);//右端点不超出mx时,初始半径与关于id对称的点相等
else
p[i] = 1;//等于零下面也同样会变成1
while (s[i + p[i]] == s[i - p[i]])
p[i]++;//p[i]-1才是半径
if (i + p[i] > mx)
id = i, mx = i + p[i];
if (r < p[i] - 1)
r = p[i] - 1, mid = i;
}
if (r < 2)
{
printf("No solution!\n");
continue;
}
int cha = c - 'a';
int st = (mid - r - 1) / 2;//st*2+2=mid-r+1
int ed = (mid + r - 3) / 2;//ed*2+2=mid+r-1
printf("%d %d\n", st, ed);
for (int i = mid - r + 1; i <= mid + r - 1; i += 2)
{
s[i] -= cha;
if (s[i] < 'a')
s[i] += 26;
printf("%c", s[i]);
}
printf("\n");
}
return 0;
}

HDU 3294 Girls' research(manachar模板题)的更多相关文章

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

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

  2. hdu 3294 Girls' research(manacher)

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

  3. HDU 3294 Girls' research

    题目地址 manacher #include<cstdio> #include<string.h> #include<algorithm> using namesp ...

  4. HDU 2222(AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串.问匹配串中含有多少个模式串.注意模式串有重复,所以要累计重复结果. 解题 ...

  5. HDU 5521.Meeting 最短路模板题

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  6. HDU 1711 - Number Sequence - [KMP模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

  7. HDU 2544 最短路(模板题——Floyd算法)

    题目: 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你 ...

  8. HDU 3966 Aragorn's Story(模板题)【树链剖分】+【线段树】

    <题目链接> 题目大意: 给定一颗带点权的树,进行两种操作,一是给定树上一段路径,对其上每个点的点权增加或者减少一个数,二是对某个编号点的点权进行查询. 解题分析: 树链剖分的模板题,还不 ...

  9. HDU 1711Number Sequence【KMP模板题】

    <题目链接> 题目大意: 意思是给出两个串,找出匹配串在模式串中的位置. 解题分析: KMP算法模板题. #include <cstdio> #include <cstr ...

随机推荐

  1. valueForKeyPath用途

    可能大家对- (id)valueForKeyPath:(NSString *)keyPath方法不是很了解. 其实这个方法非常的强大,举个例子: NSArray *array = @[@"n ...

  2. android中常用的优秀功能 (AsyncTask)

    1.用好 AsyncTask 一个优秀的android app,肯定少不了一个很好的用户体验,除了界面等外,流畅的交互,快速响应的速度都是至关重要,若 是加载一个数据,都得等上几秒钟,怕是app卸载率 ...

  3. sqlserver开窗函数在财务对账中的用法

    曾几何时发现开窗函数在财务对账总特别好用.但是每次可能很久没用,逻辑都要重头来过.特此留一份完整的思考逻辑待日后参考. 以下是数据源: 从上面的数据可以看到通过C列,那么只需要两个条件即可获得已经用对 ...

  4. codevs 1081 线段树练习2 (线段树)

    题目: 题目描述 Description 给你N个数,有两种操作 1:给区间[a,b]的所有数都增加X 2:询问第i个数是什么? 输入描述 Input Description 第一行一个正整数n,接下 ...

  5. WAV文件有多大?MP3文件有多大?使用Lame 压缩比是多少?

    一.说明: 录音文件大小多少?用什么存比较合?我有500G的硬盘存录音能存多久?...... 这些东西常用常忘,索性一次性就分析清楚记下来,方便以后查阅,如果能帮到大家那就更好了. 二.计算方法:   ...

  6. sql拼接显示table的多个列

    SELECT DeptName AS text,CONVERT(VARCHAR(10),ID)+','+DeptCode+','+ISNULL(Remark,'') AS tags,'' AS hre ...

  7. elasticsearch中的java.io.IOException: 远程主机强迫关闭了一个现有的连接

    [2018-07-31T14:29:41,289][WARN ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [9rTGh-y] caught exc ...

  8. (转)dubbo远程调用细节

    作者: 白文志 (来自开源社区) 服务提供者暴露一个服务的详细过程 上图是服务提供者暴露服务的主过程:首先ServiceConfig类拿到对外提供服务的实际类ref(如:HelloWorldImpl) ...

  9. SqlBulkCopy 之 Received an invalid column length from the bcp client for colid 5.

    SqlBulkCopy 批量复制报错: Received an invalid column length from the bcp client for colid 5. 翻译:从bcp客户端收到一 ...

  10. Confluence 6 通过 SSL 或 HTTPS 运行 - 备注和问题解决

    备注 在创建证书时候的背景信息: 'keytool -genkeypair' 命令将会创建秘钥对,包括公钥和关联的私钥,然后存储到  keystore 中.这个命令打包公钥为  X.509 v3 自签 ...