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. [AX2012]Report data provider调试

    运行使用RDP作为数据源的报表时,RDP类被编译成.NET的服务调用,RDP是X++的代码,它的调试是在MorphX调试器中完成.要在MorphX调试器中调试RDP的X++代码需要以下配置: 添加AO ...

  2. xsocks 64位平台下编译问题小记

    1.src/common/public.h uint32_t lpParameter 改为 void* lpParameter; 2.SocksMgr.cpp DWORD WINAPI CSocksM ...

  3. Tomcat and solr 环境配置

    Tomcat and solr tomcat 安装 下载安装tomcat8.0 http://tomcat.apache.org/download-80.cgi wget http://apache. ...

  4. CISA 信息系统审计知识点 [第一章. 信息系统审计过程 ]

    对有志成为审计师或者IT管理者de朋友, 第一章. 信息系统审计过程 1. IS 审计和保障标准.指南.工具.职业道德规范 信息技术保证框架(ITAF,Information Technology A ...

  5. Android使用BLE(低功耗蓝牙,Bluetooth Low Energy)

    背景 在学习BLE的过程中,积累了一些心得的DEMO,放到Github,形成本文.感兴趣的同学可以下载到源代码. github: https://github.com/vir56k/bluetooth ...

  6. lua中得栈

    如果你看了LUA的文档,那么就应该很清楚LUA与C交互数据时都是用到LUA中所谓的stack.那么当我调用lua_open函数之后栈是什么样的呢?空的(luaopen_base等会往栈上加进一些东西) ...

  7. 使用 Windows10 自定义交互消息通知

    消息通知是最常用的应用功能之一了,但是由于平台的差异,IOS Android 以及 Windows 都有其特殊性,Android开发者在国内常常都是使用三方的一些推送服务,或者是使用自建的服务器为应用 ...

  8. Unix sed实用教程开篇

    已经看了一段时间的Linux Shell编程了,也能完成一些基本的使用,为了加深理解,恰好看到了The Unix School的一个sed&awk教程,不是简单的命令参数堆积,而是一个相当实用 ...

  9. [原]SQLite的学习系列之获取数据库版本

    最先了解到SQLite是基于其作为移动客户端数据存储平台,以下是其官网(https://www.sqlite.org/)关于SQLite的一段介绍: SQLite是遵守ACID的轻型数据库引擎,它包含 ...

  10. sudo: /etc/sudoers is mode 0777, should be 0440终极解决之道

    不得不说,有时候手贱的把/etc/sudoers文件权限改了,是一件很蛋疼的事.因为此时你会发现无论做什么都会弹出一条讨厌的提示,说没有权限执行等等... 网上有介绍登入root用户,或者去grub的 ...