[manacher] hdu 3294 Girls' research
题意:
给一个字符x代表真实的a 然后输出的时候转换
然后就是求最长回文子串的串是什么 长度要大于1
思路:
就是裸的manacher,弄清楚下标的转换关系就好了
代码:
#include"cstdlib"
#include"cstdio"
#include"cstring"
#include"cmath"
#include"queue"
#include"algorithm"
#include"map"
#include"vector"
#include"string"
#define inf 0x7fffffff
#include"iostream"
#define ll __int64
using namespace std;
#define N 200005
char a[N],b[N*2];
int rad[N*2];
int main()
{
char x[2];
while(scanf("%s%s",x,&a[1])!=-1)
{
int maxl,maxid,id;
int i,len;
for(i=1; a[i]; i++)
{
b[i*2]=a[i];
b[i*2+1]='#';
}
len=2*i;
b[0]='?';
b[1]='#';
b[len]='\0';
maxid=id=0;
maxl=0;
int ansi;
for(i=1; i<len; i++)
{
if(maxid>i) rad[i]=min(rad[2*id-i],maxid-i);
else rad[i]=1;
while(b[i-rad[i]]==b[i+rad[i]])
{
rad[i]++;
}
if(rad[i]+i>maxid)
{
maxid=rad[i]+i;
id=i;
}
if(rad[i]>maxl)
{
maxl=rad[i];
ansi=i;
}
}
if(maxl-1<2) puts("No solution!");
else
{
int kk=x[0]-'a';
int ans=maxl-1,ansl,ansr;
ansl=(ansi-(ans-1))/2-1;
ansr=ansl+ans-1;
printf("%d %d\n",ansl,ansr);
for(int i=ansl; i<=ansr; i++)
{
if(a[i+1]-kk<'a') printf("%c",'z'+1-'a'+(a[i+1]-kk));
else printf("%c",a[i+1]-kk);
}
puts("");
}
}
return 0;
}
[manacher] hdu 3294 Girls' research的更多相关文章
- hdu 3294 Girls' research
#include<stdio.h> #include<string.h> #define MAX 200020 char s[MAX],ss[MAX*2],str[2]; in ...
- Hdu 3294 Girls' research (manacher 最长回文串)
题目链接: Hdu 3294 Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.... ...
- hdu 3294 Girls' research(manacher)
Problem Description One day, sailormoon girls are so delighted that they intend to research about pa ...
- HDU 3294 Girls' research(manachar模板题)
Girls' researchTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- HDU 3294 Girls' research
题目地址 manacher #include<cstdio> #include<string.h> #include<algorithm> using namesp ...
- (回文串 Manacher )Girls' research -- hdu -- 3294
http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit:1000MS Memory Limit:32 ...
- Girls' research(马拉车算法) hdu 3294
文章目录 思路如下 Manachar代码注释 题解如下 Problem Description One day, sailormoon girls are so delighted that they ...
- Manacher 算法(hdu 3068 && hdu 3294)
今天打算补前晚 BC 的第二题,发现要用到能在 O(n) 时间求最大回文子串长度的 Manacher 算法,第一次听,于是便去百度了下,看了大半天,总算能看懂了其思想,至于他给出的代码模板我没能完全看 ...
- HDU 3294 (Manacher) Girls' research
变形的求最大回文子串,要求输出两个端点. 我觉得把'b'定义为真正的'a'是件很无聊的事,因为这并不会影响到最大回文子串的长度和位置,只是在输出的时候设置了一些不必要的障碍. 另外要注意一下原字符串s ...
随机推荐
- qt: flush: BitBlt failed
"BitBlt" is a graphics accelerator function. The message is a warning, not an error. It te ...
- Java基础知识强化67:基本类型包装类之Integer直接赋值的面试题
1. 面试题: Integer i = 1: i += 1: 做了哪些事情? (1)其中Integer i =1:做了自动装箱( 使用valueOf()方法,int ---> Integer ...
- 常用分组函数count-avg-sum-max-min
分组函数也称多行函数,用于对一组数据进行运算,针对一组数据(取自于多行记录的相同字段)只返回一个结果,例如计算公司全体员工的工资总和.最高工资.最低工资.各部门的员工平均工资(按部门分组)等.由于分组 ...
- CentOS6.X 系统安装图文教程,超详细
http://www.myhack58.com/Article/sort099/sort0102/2011/32363_7.htm
- DateBox( 日期输入框) 组件
本节课重点了解 EasyUI 中 DateBox(日期输入框)组件的使用方法,这个组件依赖于 Combo(自定义下拉框)和 Calendar(日历). 一. 加载方式//class 加载方式<i ...
- Access to the path '....' is denied.解决方法
昨天公司项目迁移服务器,从自己服务器迁移到阿里云服务器,部署完成后发现有一个页面要读取磁盘上的静态文件就报错了... 如图: 解决办法: 在 Web.Config 的 <System.Web&g ...
- Objective-C Delegate
ios设计模式中的委托 Delegate 官方文档解释如下: Delegation is a simple and powerful pattern in which one object in a ...
- myEclipse笔记(1):优化配置
一.设置字体 Window->Preferences->General->Appearance->Colors and Fonts 在右侧找到”Aa Test Font”双击或 ...
- (原)python中matplotlib的颜色及线条控制
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6117528.html 参考网址: http://stackoverflow.com/questions ...
- 一个简单C程序的汇编代码分析
几个重要的寄存器 eip - 用于存放当前所执行的指令地址 esp - 栈(顶)指针寄存器 ebp - 基址(栈底)指针寄存器 简单的C程序 int g(int x) { ; } int f(int ...