链接:

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

题意:

  吉哥又想出了一个新的完美队形游戏!

  假设有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]。

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

思路:

马拉车算法扩展时增加判断条件, 不满足条件时, 直接退出.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <sstream>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 2e5+10; int a[MAXN], b[MAXN];
int Hw[MAXN];
int n; void Manacher(int *ori, int len)
{
int maxr = 0, mid;
for (int i = 1;i < len;i++)
{
if (i < maxr)
Hw[i] = min(Hw[mid*2-i], maxr-i);
else
Hw[i] = 1;
while (ori[i-Hw[i]] == ori[i+Hw[i]])
{
if (ori[i-Hw[i]] != -1 && ori[i-Hw[i]] > ori[i-Hw[i]+2])
break;
Hw[i]++;
}
if (Hw[i]+i > maxr)
{
maxr = i+Hw[i];
mid = i;
}
}
} void Change(int *ori, int *pet, int len)
{
pet[0] = pet[1] = -1;
for (int i = 0;i < len;i++)
{
pet[i*2+2] = ori[i];
pet[i*2+3] = -1;
}
pet[len*2+2] = 0;
} int main()
{
int t;
scanf("%d", &t);
while (t--)
{
memset(b, 0, sizeof(b));
scanf("%d", &n);
for (int i = 0;i < n;i++)
scanf("%d", &a[i]);
Change(a, b, n);
Manacher(b, n*2+2);
int ans = 0;
for (int i = 0;i < n*2+2;i++)
ans = max(ans, Hw[i]);
printf("%d\n", ans-1);
} return 0;
}

HDU-4513-完美队形2(Manacher变形)的更多相关文章

  1. Hdu 4513 吉哥系列故事——完美队形II (manacher变形)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4513 题目描述: 打完题目描述了,点开题目,发现题目是中文,orz.jpg.果断又删掉了,习惯真可怕 ...

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

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

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

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

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

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

  5. hdu4513完美队形II manacher

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

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

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

  7. V - 吉哥系列故事――完美队形I Manacher

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

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

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

  9. HDU 4513 吉哥系列故事——完美队形II (Manacher变形)

    题意:假设有n个人按顺序的身高分别是h[1], h[2] ... h[n],从中挑出一些人形成一个新的队形,新的队形若满足以下要求,则就是新的完美队形:  1.连续的 2.形成回文串 3.从左到中间那 ...

随机推荐

  1. Linux下nginx配置https协议访问的方法

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

  2. [转帖]图解SSL/TLS协议

    图解SSL/TLS协议   作者: 阮一峰 日期: 2014年9月20日 感谢 腾讯课堂NEXT学院 赞助本站,腾讯官方的前端课程 免费试学. http://www.ruanyifeng.com/bl ...

  3. 代码中 方法 处提示:This method has a constructor name

    “此方法具有构造方法的名字” package classpackage; public class Puppy { public void Puppy(String name) { System.ou ...

  4. XOR Guessing(交互题+思维)Educational Codeforces Round 71 (Rated for Div. 2)

    题意:https://codeforc.es/contest/1207/problem/E 答案guessing(0~2^14-1) 有两次机会,内次必须输出不同的100个数,每次系统会随机挑一个你给 ...

  5. stalstack

    Saltstack 是干什么的 saltstack 是一个开源异构平台基础设置管理工具 Saltstack 能干什么 如果是一个管理成千上百服务器的管理员,你会遇到场景 需要在每台服务器上面部署age ...

  6. X86逆向13:向程序中插入Dll

    本章我们将学习Dll的注入技巧,我们将把一个动态链接库永久的插入到目标程序中,让程序在运行后直接执行这个Dll文件,这一章的内容也可以看作是第八课的加强篇,第八课中我们向程序中插入了一个弹窗,有木有发 ...

  7. Python 风格指南

    https://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/contents/ 目前个人遵循的基本规范 ...

  8. C#将字符串格式化为Json

    private string ConvertStringToJson(string str)        {            //格式化json字符串            JsonSeria ...

  9. Unexpected console statement (no-console)

    在vue cli项目中用consloe.log()打印,启动项目报错 export default { name: 'app', components: { }, created() { this.t ...

  10. 读micro8的一些记录与思考

    最近做了一段时间的攻击,个人对于整个攻击链相对来说还是比较熟悉.看了侯师傅的文章还是学到一些,做个备忘. 1.