HDU 3294 Manacher模版题
题意:求最长回文子串所在的区间,然后第一个字符代表a,以后的顺推,最后输出这个区间顺推后的串
思路:Manacher轻松水过。记录下最长回文串的位置和长度即可了,然后输出时自己处理一下,大水题.......
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=200010;
char str[maxn],tmp[maxn<<1];
int len1[maxn<<1],pos;
int init(char *st){
int len=strlen(st);
tmp[0]='@';
for(int i=1;i<=2*len;i+=2){
tmp[i]='#';
tmp[i+1]=st[i/2];
}
tmp[2*len+1]='#';
tmp[2*len+2]='$';
tmp[2*len+3]=0;
return 2*len+1;
}
int Manacher(char *st,int len){
int p=0,ans=0,po=0;
for(int i=1;i<=len;i++){
if(p>i) len1[i]=min(p-i,len1[2*po-i]);
else len1[i]=1;
while(st[i-len1[i]]==st[i+len1[i]]) len1[i]++;
if(len1[i]+i>p){
p=len1[i]+i;
po=i;
}
if(len1[i]>ans){
ans=len1[i];
pos=i;
}
}
return ans-1;
}
int main(){
char ch;
while(scanf(" %c%s",&ch,str)!=-1){
init(str);
int len=init(str);
int ans=Manacher(tmp,len);
if(ans==1) printf("No solution!\n");
else{
int le,ri;
if(pos%2==0){
le=pos/2-1-ans/2;
ri=le+ans-1;
}else{
le=pos/2-ans/2;
ri=le+ans-1;
}
printf("%d %d\n",le,ri);
int t=ch-'a';
for(int i=le;i<=ri;i++){
int k=str[i]-t;
if(k>=97) printf("%c",str[i]-t);
else printf("%c",str[i]-t+26);
}
printf("\n");
}
}
return 0;
}
HDU 3294 Manacher模版题的更多相关文章
- 最长回文 HDU - 3068 manacher 模板题
题意:找串的最长回文字串(连续) 题解:manacher版题 一些理解:首位加上任意两个字符是为了判断边界. 本算法主要是为了 1.省去奇偶分类讨论. 2.防止形如aaaaaaa的串使得暴力算法蜕化为 ...
- HDU 3294 (Manacher) Girls' research
变形的求最大回文子串,要求输出两个端点. 我觉得把'b'定义为真正的'a'是件很无聊的事,因为这并不会影响到最大回文子串的长度和位置,只是在输出的时候设置了一些不必要的障碍. 另外要注意一下原字符串s ...
- Girls' research HDU - 3294(马拉车水题)
题意: 求最长回文串 长度要大于等于2 且输出起点和终点 输出回文串字符 这个字符还是要以给出的字符为起点a 输出 解析: 分析一下s_new串就好了 #include <iostream& ...
- hdu 3294 manacher 求回文串
感谢: http://blog.csdn.net/ggggiqnypgjg/article/details/6645824/ O(n)求给定字符串的以每个位置为中心的回文串长度. 中心思想:每次计算位 ...
- Manacher 算法(hdu 3068 && hdu 3294)
今天打算补前晚 BC 的第二题,发现要用到能在 O(n) 时间求最大回文子串长度的 Manacher 算法,第一次听,于是便去百度了下,看了大半天,总算能看懂了其思想,至于他给出的代码模板我没能完全看 ...
- HDU 2222 Keywords Search(AC自动机模版题)
Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- HDU 1712 ACboy needs your help (分组背包模版题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...
- (回文串 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 (manacher 最长回文串)
题目链接: Hdu 3294 Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.... ...
随机推荐
- Linux 倒引号、单引号、双引号
1.倒引号表示命令,用于命令替换,获取命令的返回结果. echo now is `date` 或者 echo now is $(date) 2.单引号 name=Andy 没有问题, 如果想 nam ...
- 解决Eclipse下不自动拷贝apk到模拟器问题( The connection to adb is down, and a severe error has occured)
如题 解决方案如下: 1.先把eclipse关闭.2.在管理器转到你的android SDK 的platform-tools下3.键入adb kill-server ,如果adb关闭了会提示 serv ...
- hdu1700 Points on Cycle (数学)
Problem Description There is a cycle with its center on the origin. Now give you a point on the cycl ...
- cordova百度地图定位Android版插件
本插件利用百度地图提供的定位功能进行Android版手机定位. 为什么没有iOS版? 因为iOS版有官方的定位插件cordova-plugin-geolocation可以使用. 请参照:cordova ...
- leetcode第一刷_Combination Sum Combination Sum II
啊啊啊啊.好怀念这样的用递归保存路径然后打印出来的题目啊.好久没遇到了. 分了两种,一种是能够反复使用数组中数字的,一种是每一个数字仅仅能用一次的.事实上没有多大差别,第一种每次进入递归的时候都要从头 ...
- c++11 学习
#include <iostream> // std::cout #include <functional> // std::ref #include <thread&g ...
- 关于DevOps你必须知道的11件事
转自:http://www.infoq.com/cn/articles/11devops 关于作者 Gene Kim在多个角色上屡获殊荣:CTO.研究者和作家.他曾是Tripwire的创始人并担任了1 ...
- nginx location静态文件配置
进入nginx安装目录的conf目录下,修改nginx.conf文件,在一个server{}中添加 一个location 部分配置代码如下 root@ubuntu:/usr/local/nginx/c ...
- Js实现AES/RSA加密
1. function aesEncrypt(text, secKey) { var key = CryptoJS.enc.Utf8.parse(secKey); var iv = CryptoJS. ...
- Python-装饰器进阶
基本概念 具体概念请先看之前的文章 理解装饰器 装饰器是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典的有插入日志.性能测试.事务处理, Web权限校验, Cache等. 很有名的例子,就 ...