HDU   3294

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!
 
Author
wangjing1111
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  3293 3288 3295 3292 3291 
 
题意:给了一个字符串,求这个字符串的最长回文串的始末位置,输出起始结束位置,然后根据对应原则('b'是真正的'a', 接着'c' 是真正的 'b', 'd' 是真正的 'c' ……, 'a' 是真正的 'z') ,输出这个最长回文子串;
 
思路:按照回文串模板算法,得到以每个字符为中心的最长回文串长度,然后可以遍历这个p[]数组,找到最大值即对应坐标,然后便可计算出始末位置了。最后可根据数学求余,得到每个字符的对应字符,输出回文字符子串;
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=;
int n,p[*N];
char c[],s[*N],str[*N]; void kp()
{
int i;
int mx=;
int id;
for(i=n;str[i]!=;i++)
str[i]=; ///没有这一句有问题,就过不了ural1297,比如数据:ababa aba;
for(i=;i<n;i++)
{
if(mx>i)
p[i]=min(p[*id-i],p[id]+id-i);
else
p[i]=;
for( ;str[i+p[i]]==str[i-p[i]];p[i]++);
if(p[i]+i>mx)
{
mx=p[i]+i;
id=i;
}
}
} void init()
{
str[]='$';
str[]='#';
for(int i=;i<n;i++)
{
str[i*+]=s[i];
str[i*+]='#';
}
n=n*+;
s[n]=;
} int main()
{
while(scanf("%s%s",c,s)!=EOF)
{
n=strlen(s);
init();
kp();
int ans=,sta,en=;
for(int i=;i<n;i++)
if(p[i]>ans)
en=i,ans=p[i];
///cout<<en<<" "<<ans<<endl;
if(ans-1<2) printf("No solution!\n");
else
{
sta=(en-(ans-))/-;
en=sta+ans-;
printf("%d %d\n",sta,en);
for(int i=sta;i<=en;i++)
{
s[i]=(char)((s[i]-'a'-c[]+'a'+)%+'a');
printf("%c",s[i]);
}
cout<<endl;
}
}
return ;
}
 
 

回文串--- Girls' research的更多相关文章

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

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

  2. Girls' research - HDU 3294 (Manacher处理回文串)

    题目大意:给以一个字符串,求出来这个字符串的最长回文串,不过这个字符串不是原串,而是转换过的,转换的原则就是先给一个字符 例如 'b' 意思就是字符把字符b转换成字符 a,那么c->b, d-& ...

  3. Manacher(输出最长回文串及下标)

    http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit: 3000/1000 MS (Java/Others ...

  4. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  5. [LeetCode] Shortest Palindrome 最短回文串

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  6. [LeetCode] Palindrome Partitioning II 拆分回文串之二

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  7. [LeetCode] Palindrome Partitioning 拆分回文串

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  8. [LeetCode] Longest Palindromic Substring 最长回文串

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  9. bzoj 3676 回文串 manachar+hash

    考虑每个回文串,它一定是它中心字母的最长回文串两侧去掉同样数量的字符后的一个子串. 所以我们可以用manachar求出每一位的回文半径,放到哈希表里并标记出它的下一个子串. 最后拓扑排序递推就行了.. ...

随机推荐

  1. cordova混合开发:Android中native调用javascript

    今天学习怎么在java中调用javascript方法,做个记录: 第一种方式,这个最简单: loadUrl("javascript:func1()"); 要注意要在devicere ...

  2. 使用wireshark抓取wcf生成的soap消息

    在使用wcf的时候想看下生成的soap的格式是怎样的,就想到了抓包. 平时用惯的抓包工具是需要破解,另外有时会不太好用. 于是就想起来用wireshark. 首先遇到几个问题: 1.wireshart ...

  3. Newtonsoft 自定义输出内容

    高级用法 1.忽略某些属性 2.默认值的处理 3.空值的处理 4.支持非公共成员 5.日期处理 6.自定义序列化的字段名称 7.动态决定属性是否序列化 8.枚举值的自定义格式化问题 9.自定义类型转换 ...

  4. [转]LINQ之路系列博客导航

    分享一个学习Linq的好博客:Linq之路

  5. ODAC (V9.5.15) 学习笔记(二十一)数据复制

    用TVirtualTable在内存中缓存TOraQuery中的数据,主要应用场景是参照其他数据,需要将TOraQuery中的数据复制到TVirtualTable,由于没有类似于TClientDataS ...

  6. iOS开源项目教程大合集

    UI篇 1.MMDrawerController http://www.cnblogs.com/shangdahao/p/3142204.html 2.SVPullToRefresh http://w ...

  7. Asp.net mvc 各个组件的分离

    1. 系统常见的分层 在开发asp.net mvc应用的时候,visual studio 给我们创建了默认的文档结构,一般情况下我们在一个项目下工作,参考微软的官方例子:ContosoUniversi ...

  8. 一个程序说明标准i/O缓冲的效率

    来瞧一个程序,了解一下标准I/O中的缓冲区对程序运行的影响: #include<stdio.h>#include<unistd.h> int main(){ char a[2] ...

  9. 解决方法:64位系统-未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序

    win7或win8 64位下调试程序,出现这样的错误提示:未在本地计算机上注册 Microsoft.Jet.OLEDB.4.0 提供程序 解决方法如下: 方法一:“设置应用程序池默认属性”/“常规”/ ...

  10. jquery getJSON

    function onNodeClick(data) {            //只能选择体检分组            if (data.GroupType == 1) {             ...