http://acm.hdu.edu.cn/showproblem.php?pid=4513

吉哥系列故事——完美队形II

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1544    Accepted Submission(s): 577

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

  1、挑出的人保持原队形的相对顺序不变,且必须都是在原队形中连续的;
  2、左右对称,假设有m个人形成新的队形,则第1个人和第m个人身高相同,第2个人和第m-1个人身高相同,依此类推,当然如果m是奇数,中间那个人可以任意;
  3、从左到中间那个人,身高需保证不下降,如果用H表示新队形的高度,则H[1] <= H[2] <= H[3] .... <= H[mid]。

  现在吉哥想知道:最多能选出多少人组成新的完美队形呢?

 
Input
  输入数据第一行包含一个整数T,表示总共有T组测试数据(T <= 20);
  每组数据首先是一个整数n(1 <= n <= 100000),表示原先队形的人数,接下来一行输入n个整数,表示原队形从左到右站的人的身高(50 <= h <= 250,不排除特别矮小和高大的)。
 
Output
  请输出能组成完美队形的最多人数,每组输出占一行。
 
Sample Input
2
3
51 52 51
4
51 52 52 51
 
Sample Output
3
4
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<algorithm>
  5.  
  6. using namespace std;
  7. #define INF 0x3f3f3f3f
  8. #define N 2000007
  9.  
  10. int s[N], S[N], p[N];
  11.  
  12. int Manacher(int len)
  13. {
  14. int MaxLen = , index = , ans = ;
  15.  
  16. for(int i=; i<len; i++)
  17. {
  18. if(MaxLen>i) p[i] = min(p[index*-i], MaxLen-i);
  19. else p[i] = ;
  20.  
  21. while(s[i-p[i]]==s[i+p[i]] && (s[i-p[i]]==- || p[i]== || s[i-p[i]]<=s[i-p[i]+]))
  22. p[i]++;
  23.  
  24. if(p[i]+i>MaxLen)
  25. {
  26. MaxLen = p[i] + i;
  27. index = i;
  28. }
  29.  
  30. ans = max(ans, p[i]);
  31. }
  32. return ans-;
  33. }
  34.  
  35. int main()
  36. {
  37. int t;
  38. scanf("%d", &t);
  39. while(t--)
  40. {
  41. int n, i;
  42.  
  43. scanf("%d", &n);
  44. s[] = INF;
  45. for(i=; i<n; i++)
  46. {
  47. scanf("%d", &S[i]);
  48. s[i*+] = -;
  49. s[i*+] = S[i];
  50. }
  51. s[i*+] = -;
  52. s[i*+] = -INF;
  53.  
  54. printf("%d\n", Manacher(n*+));
  55. }
  56. return ;
  57. }

(回文串 Manacher)吉哥系列故事——完美队形II -- hdu -- 4513的更多相关文章

  1. 吉哥系列故事――完美队形II HDU - 4513(马拉车变一下形)

    题意: 求最长回文串...但这个回文串要符合从中间到两头 逐个递减 解析: 在扩散的时候加一个判断就好了 #include <iostream> #include <cstdio&g ...

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

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

  3. HDU 4513 吉哥系列故事――完美队形II(Manacher)

    题目链接:cid=70325#problem/V">[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher V - 吉哥系列故事――完美队形I ...

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

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

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

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

  6. HDU 4513 吉哥系列故事——完美队形II manacher

    吉哥系列故事——完美队形II Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希 ...

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

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

  8. hdu 4513 吉哥系列故事——完美队形II (manachar算法)

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

  9. HDU 4513 吉哥系列故事――完美队形II

    http://acm.hdu.edu.cn/showproblem.php?pid=4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) ...

随机推荐

  1. scala 建模

    // train multinomial logistic regression val lr = new LogisticRegressionWithLBFGS() .setIntercept(tr ...

  2. dom node 查找父级parentNode

    var o = document.querySelectorAll("a[href='baidu.com']"); var p = o[o.length-1];console.lo ...

  3. Mysql delete操作

    以下摘自官方文档:https://dev.mysql.com/doc/refman/5.7/en/insert.html 语法: DELETE [LOW_PRIORITY] [QUICK] [IGNO ...

  4. python简单基础代码

    1.从键盘输入两个数,并计算A的B次幂:number1=raw_input('input number1:')number2=raw_input('input number2:')print 'num ...

  5. cin 不能直接读入空格,可以用getline(PAT统计字符数)

    #include <iostream>#include <cstring>using namespace std; int main(){    string str;     ...

  6. 演示Spring框架的JDBC模板的简单操作

    1. 步骤一:创建数据库的表结构 create database spring_day03; use spring_day03; create table t_account( id int prim ...

  7. 750A New Year and Hurry

    A. New Year and Hurry time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. python使用wmi模块获取windows下的系统信息监控系统-乾颐堂

    Python用WMI模块获取Windows系统的硬件信息:硬盘分区.使用情况,内存大小,CPU型号,当前运行的进程,自启动程序及位置,系统的版本等信息. 本文实例讲述了python使用wmi模块获取w ...

  9. WinScp获取一个文件

    CD /d C:\Program Files (x86)\WinSCPWinSCP.exe /console /command "option batch continue" &q ...

  10. DNS/BIND in Debian

    Debian official document:http://www.debian.org/doc/manuals/network-administrator/ch-bind.html Buildi ...