回文串--- 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求出每一位的回文半径,放到哈希表里并标记出它的下一个子串. 最后拓扑排序递推就行了.. ...
随机推荐
- JQuery 表格拖动调整列宽效果
类似于桌面程序中的表格拖动表头的效果,当鼠标停留在表头边框线上时,鼠标会变成表示左右拖动的形状,接着拖动鼠标,会在表格中出现一条随鼠标移动的竖线,最后放开鼠标,表格列宽会被调整.最近比较空闲,便自己动 ...
- 调用 webapi的put和delete 报"Method Not Allowed" 405 错误。
修改引用到webapi的Dll文件对应的项目的web.config 选择生成读写方法webapi会生成四个读写的方法(CRUD),两个获取数据的.一个更新.一个删除,默认情况下更新和删除是不对外开外的 ...
- How to Debug Enterprise Portal Code in Dynamics AX 2009
转载 To set up debugging for pages1. Log into the server that is running the AOS.2. Open the Microsoft ...
- 解决eclipse中android添加重载函数时参数为arg0,arg1的问题
遇到同样的问题,发现有人已经解决了,大体意思就是为android sdk 添加 src,以下是文章链接 http://blog.csdn.net/u014084081/article/details/ ...
- java8 函数式编程
/*** * 测试统计API <br> * 小结:<br> * 1.逻辑代码应用{} 包起来 不写{} 默认 + return <br> * 2.重载方法参数必须加 ...
- java框架篇---spring hibernate整合
在会使用hibernate 和spring框架后 两个框架的整合就变的相当容易了, 为什么要整合Hibernate?1.使用Spring的IOC功能管理SessionFactory对象 LocalSe ...
- JavaScript面试库
1.将一段字符串转成驼峰命名法. var str = "web-kit-index"; function to(str){ var j = str.split("-&qu ...
- 没有Google的日子很难过...But you can try...
作为开发人员,经常会通过Google查询一些资料(别问我为什么不用百度,当你输入关键字,然后给你提示没有查询到结果,或者一页全是垃圾资料的时候你就知道了).但是,N个月前,Google不好使了,同时N ...
- [Altera] Device Part Number Format
大体可分为五个部分,不排除有特例. 第一部分说明器件归属的器件系列, 第二部分说明器件的封装类型, 第三部分说明器件的引脚数目, 第四部分说明器件的工作温度范围, 第五部分说明器件的速度等级. 实践中 ...
- 继续谈论XSS
这篇文章基于上篇谈论XSS ,想说下自己工作过程中遇到的xss的问题. 易出现XSS的场景 1 jsonp 说说jsonp 中也有说过,jsonp其实是很容易出现安全问题的.由于jsonp的callb ...