HDU----(3294)Girls' research(manacher)
Girls' research
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 537 Accepted Submission(s): 199
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<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxn 400050
char str[maxn];
int rad[maxn];
int Min(int a,int b){
return a<b?a:b;
}
void init(int len,char s[]){
memset(rad,,sizeof(int)*(*len+));
s[len*+]='\0';
int i,j=;
for(i=len*+;i>;i--){
if(i&) s[i]='#';
else{ s[i]=s[len-j];
j++;
}
}
s[]='$'; //防止溢出
}
int manacher(int len){
int id,i,ans=;
for(i=;i<len*+;i++){
if(id+rad[id]>i) rad[i]=Min(rad[id*-i],id+rad[id]-i);
while(str[i-rad[i]]==str[i+rad[i]]) rad[i]++;
if(i+rad[i]>id+rad[id]) id=i;
if(ans<rad[i])ans=rad[i];
}
return ans;
}
int main(){
char sav[];
int len,i;
//system("call test.in");
//freopen("test.in","r",stdin);
// fclose(stdin);
while(scanf("%s%s",sav,str)!=EOF){
len=strlen(str);
init(len,str);
int ans=manacher(len);
if(ans<=)puts("No solution!");
else{
for(i=;i<len*+;i++)
if(ans==rad[i]) break;
int st,en;
st=(i-ans)/;
en=st+ans-;
printf("%d %d\n",st,en);
for(int j=(st+)*;j<(st+ans)*;j+=){
if(str[j]-(sav[]-'a')<'a')
printf("%c",str[j]+('z'-sav[]+));
else
printf("%c",str[j]-(sav[]-'a'));
}
puts("");
}
}
return ;
}
HDU----(3294)Girls' research(manacher)的更多相关文章
- (回文串 Manacher )Girls' research -- hdu -- 3294
http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit:1000MS Memory Limit:32 ...
- HDU 3294 Girls' research(manachar模板题)
Girls' researchTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- 吉哥系列故事——完美队形II---hdu4513(最长回文子串manacher)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4513 题意比最长回文串就多了一个前面的人要比后面的人低这个条件,所以在p[i]++的时候判断一下s[i ...
- hdu-3068(最长回文子串-manacher)
题意:求一个字符串#include<iostream>#include<algorithm>#include<cstring>using namespace std ...
- Hdu 3294 Girls' research (manacher 最长回文串)
题目链接: Hdu 3294 Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.... ...
- HDU 3948 The Number of Palindromes(Manacher+后缀数组)
题意 求一个字符串中本质不同的回文子串的个数. $ 1\leq |string| \leq 100000$ 思路 好像是回文自动机的裸题,但是可以用 \(\text{Manacher}\) (马拉车) ...
- HDU - 3068 最长回文(manacher算法)
题意:给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度. 分析: manacher算法: 1.将字符串中每个字符的两边都插入一个特殊字符.(此操作的目的是,将字符串 ...
- 【HDU 4352】 XHXJ's LIS (数位DP+状态压缩+LIS)
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 3416 Marriage Match IV (最短路径,网络流,最大流)
HDU 3416 Marriage Match IV (最短路径,网络流,最大流) Description Do not sincere non-interference. Like that sho ...
随机推荐
- jquery append()详解
1 http://www.365mini.com/page/jquery-append.htm 2 http://blog.csdn.net/chaiyining007/article/details ...
- DataSet.Clear Method ()
Clears the DataSet of any data by removing all rows in all tables. 需要注意的是这个方法不会清空DataSet中的DataTable, ...
- CSS选择器、优先级与匹配原理(转)
CSS选择器.优先级与匹配原理 导航 为了分析Bootstrap源码,所以的先把CSS选择器相关的东东给巩固好 废话就不多说了 CSS 2.1 selectors, Part 1 计算指定选择器的优先 ...
- 测试框架Mockito使用笔记
Mockito,测试框架,语法简单,功能强大! 静态.私有.构造等方法测试需要配合PowerMock,PowerMock有Mockito和EasyMock两个版本,语法相同,本文只介绍Mockito. ...
- Entity Framework(1)
Web.Config配置 <dataConfiguration defaultDatabase="strConn"> <providerMappings> ...
- iOS - OC NSDictionary 字典
前言 @interface NSDictionary<__covariant KeyType, __covariant ObjectType> : NSObject <NSCopyi ...
- 关于JAVA中URL传递中文参数,取值是乱码的解决办法
前几天看到有网友在问URLDecoder和URLEncoder方面的使用问题,突然想起,原来我刚遇到这两个类时,也觉得很神密,由此可以想想初学者的心情,于是便有了今天的这篇文章. 其实,这两个类的使用 ...
- for循坏的穷举与迭代,while、do while循环
for循环的穷举:所有情况走一遍,使用if筛选出符合的情况. 单位发一张150元购物卡,到超市买三种洗化用品,洗发水15元,香皂两元,牙刷5元,刚好花完150元,有多少种买法,每种买法各买几样. 百鸡 ...
- Ajax异步调用使用
//验证通知号重复 function checkinformcodeagage() { var informcode = $("#txtinformcode").val(); if ...
- JS 对象(Object)和字符串(String)互转
利用原生JSON对象,将对象转为字符串 var jsObj = {}; jsObj.testArray = [1,2,3,4,5]; jsObj.name = 'CSS3'; jsObj.date = ...