回文串--- Girls' research
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.
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.
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.
#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的更多相关文章
- Hdu 3294 Girls' research (manacher 最长回文串)
题目链接: Hdu 3294 Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.... ...
- Girls' research - HDU 3294 (Manacher处理回文串)
题目大意:给以一个字符串,求出来这个字符串的最长回文串,不过这个字符串不是原串,而是转换过的,转换的原则就是先给一个字符 例如 'b' 意思就是字符把字符b转换成字符 a,那么c->b, d-& ...
- Manacher(输出最长回文串及下标)
http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit: 3000/1000 MS (Java/Others ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- [LeetCode] Palindrome Partitioning II 拆分回文串之二
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- [LeetCode] Palindrome Partitioning 拆分回文串
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- [LeetCode] Longest Palindromic Substring 最长回文串
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- bzoj 3676 回文串 manachar+hash
考虑每个回文串,它一定是它中心字母的最长回文串两侧去掉同样数量的字符后的一个子串. 所以我们可以用manachar求出每一位的回文半径,放到哈希表里并标记出它的下一个子串. 最后拓扑排序递推就行了.. ...
随机推荐
- IOS 开发环境,证书和授权文件等详解
(转自:http://blog.csdn.net/gtncwy/article/details/8617788) 一.成员介绍1. Certification(证书)证书是对电脑开发资格的认证, ...
- Android最佳实践之UI篇
http://sr1.me/way-to-explore/2015/03/25/best-practice-for-android-ui.html
- Oracle数据库入门——初级系列教程
- win10下LPT并口打印失败和POS打印机的钱箱不能打开,win10的坑
最近在弄一个收银软件,因为使用到了触摸屏,该PC出厂安装的是老掉牙的XP.SSD固态硬盘,装XP实在是太浪费了.然后尝试了WIN7发现不能激活,然后试win8.1发现比较满意终于觉得配得上触摸屏了,但 ...
- Ubuntu下的杀毒
Ubuntu 11.04 杀毒软件ESET NOD32 Linux防病毒,并不代表没有病毒,只是数量过少.因技术精英发现漏洞后即时打补丁,病毒很少. 有兴趣的同学可以尝试下Ubuntu 11. ...
- Redis PHP通用类
找到一个比较全的Redis PHP操作类库,分享给大家 <?php /** * redis操作类 * 说明,任何为false的串,存在redis中都是空串. * 只有在key不存在时,才会 ...
- 我的第一个Socket程序-SuperSocket使用入门(三)
本来博客都停了,不打算更了,但今天百度一个socket的问题时无意间发现第一篇的socket文章权重仅次于SuperSocket网站,顿时觉得自己6到不行,再写一篇,讨论下数据持久化的问题 去年搞那个 ...
- 【转载】[JS]让表单提交返回后保持在原来提交的位置上
有时候,在网页中点击了页面中的按钮或是刷新了页面后,页面滚动条又 会回到顶部,想看后面的记录就又要拖动滚动条,或者要按翻页键,非常不方便,想在提交页面或者在页面刷新的时候仍然保持滚动条的位置不变,最好 ...
- 蓝凌OA二次开发手册
1.蓝凌OA表单前端调用后台数据 一.后台存储过程: create procedure sp_test @ftext nvarchar(50) as begin select @ftext as '测 ...
- JS 获取一个对象里面第一层元素的数量
function getObjectLength(obj) { var i = 0; for(var k in obj){ i++; } return i; } var obj = { a: 1, b ...