题意:求一个由小写字母组成的字符串中的最长回文长度

cas<=120 n<=110000

思路:试manacher板子

 var a:array[..]of char;
p:array[..]of longint;
ch:ansistring;
len,n,i,mx,id,ans:longint; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; function max(x,y:longint):longint;
begin
if x>y then exit(x);
exit(y);
end; begin
assign(input,'hdoj3068.in'); reset(input);
assign(output,'hdoj3068.out'); rewrite(output);
while not eof do
begin
readln(ch);
len:=length(ch);
if len= then continue;
n:=; a[]:='@'; a[]:='#';
for i:= to len do
begin
inc(n); a[n]:=ch[i];
inc(n); a[n]:='#';
end;
inc(n); a[n]:='$';
mx:=; id:=;
for i:= to n- do
begin
if mx>i then p[i]:=min(p[*id-i],mx-i)
else p[i]:=;
while a[i+p[i]]=a[i-p[i]] do inc(p[i]);
if p[i]+i>mx then
begin
mx:=p[i]+i;
id:=i;
end;
end;
ans:=;
for i:= to n- do ans:=max(ans,p[i]-);
writeln(ans);
end;
close(input);
close(output);
end.

【HDOJ3068】最长回文(manacher)的更多相关文章

  1. hdu 3068 最长回文 manacher算法(视频)

    感悟: 首先我要Orz一下qsc,我在网上很难找到关于acm的教学视频,但偶然发现了这个,感觉做的很好,链接:戳戳戳 感觉这种花费自己时间去教别人的人真的很伟大. manacher算法把所有的回文都变 ...

  2. hdu 3068 最长回文 manacher

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度.回文就是正 ...

  3. HDU3068 最长回文 Manacher算法

    Manacher算法是O(n)求最长回文子串的算法,其原理很多别的博客都有介绍,代码用的是clj模板里的,写的确实是异常的简洁,现在的我只能理解个大概,下面这个网址的介绍比较接近于这个模板,以后再好好 ...

  4. hdu_3068 最长回文(Manacher算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 最长回文 Time Limit: 4000/2000 MS (Java/Others)    M ...

  5. hdu 3068 最长回文(manacher&amp;最长回文子串)

    最长回文 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  6. hdu3068 最长回文 manacher

    给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度.回文就是正反读都是一样的字符串,如aba, abba等 manacher裸题 #include<stdio. ...

  7. HDU3068 最长回文 MANACHER+回文串

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 Problem Description 给出一个只由小写英文字符a,b,c...y,z组成的字符 ...

  8. hdu-3068-最长回文(manacher算法模板)

    题目链接 /* Name:hdu-3068-最长回文 Copyright: Author: Date: 2018/4/24 16:12:45 Description: manacher算法模板 */ ...

  9. hdu 3068 最长回文(manacher入门)

    最长回文 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  10. HDU - 3068 最长回文manacher马拉车算法

    # a # b # b # a # 当我们遇到回判断最长回文字符串问题的时候,若果用暴力的方法来做,就是在字符串中间添加 #,然后遍历每一个字符,找到最长的回文字符串.那么马拉车算法就是在这个基础上进 ...

随机推荐

  1. Android 性能优化(25)*性能工具之「Systrace」Analyzing UI Performance with Systrace:用Systrace得到ui性能报告

    Analyzing UI Performance with Systrace In this document Overview 简介 Generating a Trace  生成Systrace文件 ...

  2. 406 Queue Reconstruction by Height 根据身高重建队列

    假设有打乱顺序的一群人站成一个队列. 每个人由一个整数对(h, k)表示,其中h是这个人的身高,k是排在这个人前面且身高大于或等于h的人数. 编写一个算法来重建这个队列.注意:总人数少于1100人.示 ...

  3. 记录sql操作

    需求:一个a表的A列等于b表的B列 但拥有的相同列C列值不相同 需要将其改成一样的 UPDATE vd_auth_switch vas,tb_student ts set vas.class_id = ...

  4. 385 Mini Parser 迷你解析器

    Given a nested list of integers represented as a string, implement a parser to deserialize it.Each e ...

  5. MVC学习-发送请求

    在HomeControl中添加一个Action,代码如下: public ActionResult Add() { return View(); } 当View()中不写任何参数时,默认会调用同名的视 ...

  6. ubuntu下编译VLC源码

    http://blog.csdn.net/beitiandijun/article/details/9225591ubuntu下编译VLC源码 分类: 视频处理 2013-07-02 17:33 57 ...

  7. vuex的各个细节理解(因人而异)

    应用级的状态集中放在store中: 改变状态的方式是提交mutations,这是个同步的事物: 异步逻辑应该封装在action中. const vuex_store = new Vuex.store( ...

  8. NVIDIA各个领域芯片现阶段的性能和适应范围

    NVIDIA作为老牌显卡厂商,在AI领域深耕多年.功夫不负有心人,一朝AI火,NVIDIA大爆发,NVIDIA每年送给科研院所和高校的大量显卡,大力推广Physix和CUDA,终于钓了产业的大鱼. 由 ...

  9. codeforces_456C_dp

    链接:http://codeforces.com/problemset/problem/456/C C. Boredom time limit per test 1 second memory lim ...

  10. MySql(四)Select条件查询

    select条件查询的格式如下: SELECT 查询列表FROM 表名WHERE 筛选条件:123456根据筛选条件可以分为以下几类: 按照条件按表达式进行筛选 常用条件运算符如下:> .< ...