传送门:吉哥系列故事——完美队形II

题意:求最长回文队伍且队伍由中间向两边递减。

分析:manach算法小应用,在判断回文子串向两边递减时加点限制使回文是由中间向两边递减的。

#pragma comment(linker,"/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-6
#define N 100010
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PII pair<int,int>
using namespace std;
inline LL read()
{
char ch=getchar();LL x=,f=;
while(ch>''||ch<''){if(ch=='-')f=-;ch=getchar();}
while(ch<=''&&ch>=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int p[N<<],ans,len,num,mx,id;
int a[N],c[N<<],n;
void build()
{
n=read();
for(int i=;i<n;i++)a[i]=read();
num=;
c[num++]=-;c[num++]=inf;
for(int i=;i<n;i++)
{
c[num++]=a[i];
c[num++]=inf;
}
c[num]=-;
}
void manacher()
{
ans=;mx=;
memset(p,,sizeof(p));
for(int i=;i<num;i++)
{
if(mx>i)p[i]=min(p[*id-i],mx-i);
else p[i]=;
while(c[i-p[i]]==c[i+p[i]]&&(c[i-p[i]]==inf||p[i]==||c[i-p[i]]<=c[i-p[i]+]))p[i]++;
if(p[i]+i>mx)mx=p[i]+i,id=i;
ans=max(ans,p[i]-);
}
}
int main()
{
int T;
T=read();
while(T--)
{
build();
manacher();
printf("%d\n",ans);
}
}

hdu4513(manacher)的更多相关文章

  1. 吉哥系列故事——完美队形II(hdu4513+Manacher)

    吉哥系列故事--完美队形II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) T ...

  2. HDU4513 吉哥系列故事——完美队形II Manacher算法

    题目链接:https://vjudge.net/problem/HDU-4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others)    Me ...

  3. hdu----(4513)吉哥系列故事——完美队形II(manacher(最长回文串算法))

    吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)To ...

  4. HDU4513吉哥系列故事――完美队形II(manacher算法)

    这个比最长回文子串就多了一个条件,就是回文字串(这里相当于人的高度)由两端向中间递增. 才刚刚看了看manacher,在用模板A了一道题后,还没有完全理解manacher,然后就准备把这道题也直接带模 ...

  5. hdu4513之manacher算法

    吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) T ...

  6. hdu4513完美队形II manacher

    吉哥又想出了一个新的完美队形游戏!  假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成一个新的队形,新的队形若满足以下三点要 ...

  7. HDU4513:完美队形II(Manacher)

    Description Input Output Sample Input   Sample Output   Solution 才发现我之前不会证$Manacher$复杂度……QAQ 题意是求最长向 ...

  8. HDU4513:吉哥系列故事——完美队形II(Manacher)

    吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)To ...

  9. 【回文串-Manacher】

    Manacher算法能够在O(N)的时间复杂度内得到一个字符串以任意位置为中心的回文子串.其算法的基本原理就是利用已知回文串的左半部分来推导右半部分. 转:http://blog.sina.com.c ...

随机推荐

  1. Maven项目红色叹号+JavaWeb: 报错信息The superclass &quot;javax.servlet.http.HttpServlet&quot; was not found on the Java B

    昨天写的关于解决JavaWeb: 报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the ...

  2. java对象占用内存大小计算方式

    案例一: User public class User { } UserSizeTest public class UserSizeTest { static final Runtime runTim ...

  3. 基于unity3d和leap motion的拼图游戏

    近期用unity3d引擎做了一个拼图游戏,会分几次写完,以此作为总结. 本文基本查找了网上能查到的全部资料作为參考.也算是大家节省了时间. 眼下仅仅完毕了拼图部分,leap motion手势控制部分会 ...

  4. css3圆角代码

    div+css3普通圆角代码示例 <style type="text/css"> #round { width:200px; height:100px; margin: ...

  5. JavaScript常用全局属性与方法

    最近,在学习JavaScript,Java作域链包含全局,记录下常用的全局属性与方法,就当是知识的积累,未列出全部,如需查看全部可参考JS相关的API文档. 常用的全局属性:  全局属性      作 ...

  6. 待机状态下,服务类型 WCDMA Service type in Idle mode

    Services aredistinguished into categories defined in [7]; also the categorisation of cellsaccording ...

  7. Lucene.Net 2.3.1开发介绍 —— 三、索引(四)

    原文:Lucene.Net 2.3.1开发介绍 -- 三.索引(四) 4.索引对搜索排序的影响 搜索的时候,同一个搜索关键字和同一份索引,决定了一个结果,不但决定了结果的集合,也确定了结果的顺序.那个 ...

  8. 默认情况下,不使用of子句表示在select所有的数据表中加锁(转)

    Select …forupdate语句是我们经常使用手工加锁语句.通常情况下,select语句是不会对数据加锁,妨碍影响其他的DML和DDL操作.同时,在多版本一致读机制的支持下,select语句也不 ...

  9. 14.2.5.1 Role of the .frm File for InnoDB Tables InnoDB .frm文件的作用

    14.2.5.1 Role of the .frm File for InnoDB Tables: 14.2.5.1 Role of the .frm File for InnoDB Tables I ...

  10. 【android】下载文件至本应用程序的file文件夹或者sdcard

     一.推断是否有sdcard卡 //推断是否有SD卡 //ture:有SD卡 //false:没有SD卡 public boolean avaiableMedia(){ String status ...