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

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

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

  1. #pragma comment(linker,"/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <string>
  5. #include <cmath>
  6. #include <limits.h>
  7. #include <iostream>
  8. #include <algorithm>
  9. #include <queue>
  10. #include <cstdlib>
  11. #include <stack>
  12. #include <vector>
  13. #include <set>
  14. #include <map>
  15. #define LL long long
  16. #define mod 1000000007
  17. #define inf 0x3f3f3f3f
  18. #define eps 1e-6
  19. #define N 100010
  20. #define lson l,m,rt<<1
  21. #define rson m+1,r,rt<<1|1
  22. #define PII pair<int,int>
  23. using namespace std;
  24. inline LL read()
  25. {
  26. char ch=getchar();LL x=,f=;
  27. while(ch>''||ch<''){if(ch=='-')f=-;ch=getchar();}
  28. while(ch<=''&&ch>=''){x=x*+ch-'';ch=getchar();}
  29. return x*f;
  30. }
  31. int p[N<<],ans,len,num,mx,id;
  32. int a[N],c[N<<],n;
  33. void build()
  34. {
  35. n=read();
  36. for(int i=;i<n;i++)a[i]=read();
  37. num=;
  38. c[num++]=-;c[num++]=inf;
  39. for(int i=;i<n;i++)
  40. {
  41. c[num++]=a[i];
  42. c[num++]=inf;
  43. }
  44. c[num]=-;
  45. }
  46. void manacher()
  47. {
  48. ans=;mx=;
  49. memset(p,,sizeof(p));
  50. for(int i=;i<num;i++)
  51. {
  52. if(mx>i)p[i]=min(p[*id-i],mx-i);
  53. else p[i]=;
  54. 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]++;
  55. if(p[i]+i>mx)mx=p[i]+i,id=i;
  56. ans=max(ans,p[i]-);
  57. }
  58. }
  59. int main()
  60. {
  61. int T;
  62. T=read();
  63. while(T--)
  64. {
  65. build();
  66. manacher();
  67. printf("%d\n",ans);
  68. }
  69. }

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. 【Tesseract-OCR】在VS2012环境下调用API方法---注意避免名字冲突

    由于在VS2012中使用OpenCV可以得到插件ImageWatch.vsix的支持,查看图像非常方便,所以一直想在VS2012环境下把Tesseract-OCR融合进来,但是这一错误折腾了我好久: ...

  2. 推荐国内外优秀+免费CDN加速站点及公共cdn加速库

    -----------------------------------------------------------------免费CDN加速站点 1.CloudFlare CloudFlare可能 ...

  3. asp.net2.0安全性(2)--用户个性化设置(2)--转载来自车老师

    上一篇我们用Profile.age等方式可以读取用户的年龄和其它的信息,但有的时候我们要查询显示所有用户的信息,但asp.net没有提供查询所有用户信息的功能,我们只能对现有的用户逐一查询其Profi ...

  4. PHP学习之-1.7 注释

    注释 在PHP中也有注释语句:用双斜杠 "//" 来表示.其他语言中 HTML使用 "<!--  -->" ,CSS中使用 "/*     ...

  5. poj 1018 Communication System 枚举 VS 贪心

    Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21631   Accepted:  ...

  6. TCP与UDP各自特点对比

    UDP和TCP是我们最常用的两种通信方式,下面就两者之间的特点做一个对比: 1.UDP主要用在实时性要求高以及对质量相对较弱的地方,如流媒体. 2.TCP既然是面向连接的,那么运行环境必然要求其保证可 ...

  7. iot 表 主键索引叶子块包含了表所有数据

    <pre name="code" class="html">iot表测试: 在create table语句后面使用organization inde ...

  8. 简单的ajax获取json

    一个DBhelper类,用来操作数据库 using System; using System.Collections.Generic; using System.Linq; using System. ...

  9. Qt4创建工程的几种方法:linux系统

    方法一:以Qt Creator 作为IDE 1.启动Qt Creator,并创建一个空项目 2.输入路径和工程名字 3.添加cpp文件 4.添加代码,并且编译执行 5.执行结果 方法二:利用linux ...

  10. 【翻译】十大要避免的Ext JS开发方法

    原文地址:http://www.sencha.com/blog/top-10-ext-js-development-practices-to-avoid/ 作者:Sean Lanktree Sean ...