变形的求最大回文子串,要求输出两个端点。

我觉得把'b'定义为真正的'a'是件很无聊的事,因为这并不会影响到最大回文子串的长度和位置,只是在输出的时候设置了一些不必要的障碍。

另外要注意一下原字符串s1中的字符在预处理以后的字符串s2中对应的坐标关系,这样输出的时候就可以照着这个关系转化。

轻松1A,嘿嘿

 //#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int maxn = + ;
char s1[maxn], s2[maxn * ], real;
int p[maxn * ]; void init(char s1[], char s2[])
{
int j = ;
s2[] = '$', s2[] = '#';
for(int i = ; s1[i] != '\0'; ++i)
{
s2[j++] = s1[i];
s2[j++] = '#';
}
s2[j] = '\0';
} void manacher(char s[])
{
p[] = ;
int id, mx = ;
for(int i = ; s[i] != '\0'; ++i)
{
if(mx > i)
p[i] = min(p[id*-i], mx-i);
else
p[i] = ;
while(s[i + p[i]] == s[i - p[i]])
++p[i];
if(i + p[i] > mx)
{
id = i;
mx = i + p[i];
}
}
} char change(char c)
{
c -= real - 'a';
if(c < 'a') c += ;
if(c > 'z') c -= ;
return c;
} void getans(void)
{
int mlen = , pos;
for(int i = ; s2[i] != '\0'; ++i)
{
if(p[i] - > mlen)
{
mlen = p[i] - ;
pos = i;
}
}
if(mlen == )
printf("No solution!\n");
else
{
int L = (pos - (p[pos] - )) / - ;
int R = (pos + (p[pos] - )) / - ;
printf("%d %d\n", L, R);
for(int i = L; i <= R; ++i)
printf("%c", change(s1[i]));
printf("\n");
}
} int main(void)
{
#ifdef LOCAL
freopen("3294in.txt", "r", stdin);
#endif while(scanf("%c", &real) == )
{
scanf("%s", s1);
getchar();
init(s1, s2);
manacher(s2);
getans();
}
return ;
}

代码君

HDU 3294 (Manacher) Girls' research的更多相关文章

  1. HDU 3294 Manacher模版题

    点击打开链接 题意:求最长回文子串所在的区间,然后第一个字符代表a,以后的顺推,最后输出这个区间顺推后的串 思路:Manacher轻松水过.记录下最长回文串的位置和长度即可了,然后输出时自己处理一下, ...

  2. hdu 3294 manacher 求回文串

    感谢: http://blog.csdn.net/ggggiqnypgjg/article/details/6645824/ O(n)求给定字符串的以每个位置为中心的回文串长度. 中心思想:每次计算位 ...

  3. (回文串 Manacher )Girls' research -- hdu -- 3294

    http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit:1000MS     Memory Limit:32 ...

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

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

  5. Girls' research(马拉车算法) hdu 3294

    文章目录 思路如下 Manachar代码注释 题解如下 Problem Description One day, sailormoon girls are so delighted that they ...

  6. HDU 3294 Girls' research(manachar模板题)

    Girls' researchTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...

  7. Manacher 算法(hdu 3068 && hdu 3294)

    今天打算补前晚 BC 的第二题,发现要用到能在 O(n) 时间求最大回文子串长度的 Manacher 算法,第一次听,于是便去百度了下,看了大半天,总算能看懂了其思想,至于他给出的代码模板我没能完全看 ...

  8. HDU----(3294)Girls' research(manacher)

    Girls' research Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)T ...

  9. Girls' research(manacher)

    Girls' research Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) ...

随机推荐

  1. Effeckt.css项目:CSS交互动画应用集锦

    目前,网上有大量基于CSS转换的实验和示例,但它们都过于分散,而Effeckt.css的目标就是把所有基于CSS/jQuery动画的应用集中起来,例如:弹窗.按钮.导航.列表.页面切换等等. Effe ...

  2. sql盲注及其相关方法

    Sql注入过程数据(后台数据不能回显到页面)不回显采用方法 1:构造逻辑判断 ▲left(database(),1)>’s’             //left()函数 ▲and ascii( ...

  3. List Comprehensions

    看Python高级编程时有几个东西要记一记,方便以后查询 以下代码基本全摘自Python高级编程 取0~9之间的偶数,类C语言写法: 使用list comprehensions可以极大程度上简化语法: ...

  4. 【QT】找茬外挂制作

    找茬外挂制作 找茬游戏大家肯定都很熟悉吧,两张类似的图片,找里面的不同.在下眼神不大好,经常瞪图片半天也找不到区别.于是乎决定做个辅助工具来解放一下自己的双眼. 一.使用工具 Qt:主要是用来做界面的 ...

  5. 树莓派/RaspberryPi 内核编译

    1.获取所需源码 1)下载地址: 官方网址:https://github.com/raspberrypi 上面列出了树莓派所有的开源软件: linux:内核源码 tools:编译内核和其他源码所需的工 ...

  6. UVA 11181 dfs 概率

    N friends go to the local super market together. The probability of their buying something from them ...

  7. 李洪强漫谈iOS开发[C语言-043]-判断较早日期

    李洪强漫谈iOS开发[C语言-043]-判断较早日期

  8. 窗口截图(可指定HWND窗口句柄)(三篇文章)

    BOOL SaveHwndToBmpFile(HWND hWnd, LPCTSTR lpszPath) { HWND hDesktop = ::GetDesktopWindow(); ASSERT(h ...

  9. [iOS]利用通知实现监听系统键盘

    // // ViewController.m // text // // Created by 李东旭 on 16/1/22. // Copyright © 2016年 李东旭. All rights ...

  10. iOS:UIView的block函数实现转场动画---单视图

    使用UIView动画函数实现转场动画——单视图 + (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration ...