题目链接:

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

题目描述:

  打完题目描述了,点开题目,发现题目是中文,orz.jpg。果断又删掉了,习惯真可怕.......

解题思路:

  刚开始,我先manacher求出以 i 为中心的回文串半径存入vis,然后暴力循环每一个位置是不是最长的完美队列。果断T了,胡乱改了几处依旧T。突然灵机一动,发现可以在跑vis数组的时候加一些判定条件,然后直接求出max(vis[i])即可。

  学习算法是次要,理解算法思想,锻炼思维灵敏逻辑缜密才最重要。

 #include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std; typedef long long LL;
const int maxn = ;
int vis[maxn*], a[maxn], b[maxn*]; bool judge (int x, int y)
{
for (int i=x+; i<=y/; i++)
if (a[i]<a[i-])
return false;
return true;
} void manacher (int s[], int len)
{
int l = ;
b[l ++] = -;
b[l ++] = -; for (int i=; i<len; i++)
{
b[l ++] = a[i];
b[l ++] = -;
}
b[l] = ; int mx = , id = , ans = ; for (int i=; i<l; i++)
{
vis[i] = mx > i ? min (vis[*id-i], mx-i):; while (b[i-vis[i]] == b[i+vis[i]] && (b[i-vis[i]]==- || b[i-vis[i]]<=b[i-vis[i]+])) vis[i] ++; if (i + vis[i] > mx)
{
mx = i + vis[i];
id = i;
}
ans = max (ans, vis[i]);
} printf ("%d\n", ans - );
} int main ()
{
int T, n;
scanf ("%d", &T); while (T --)
{
scanf ("%d", &n);
for (int i=; i<n; i++)
scanf ("%d", &a[i]); manacher(a, n);
}
return ;
}

Hdu 4513 吉哥系列故事——完美队形II (manacher变形)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

    链接:传送门 思路:根据完美队形的定义,可以得知,完美队形实质上是 回文串 + 序列出现峰,因为是在回文串中再次增加了一个要求,所以可以对 Manacher 进行改造,改造的部分应该为暴力匹配的循环 ...

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

    变形的Manacher算法,在扩展的时候要加入限制条件,满足题目中说的从左到中间身高不减. 其他地方倒是没有什么改动.. //#define LOCAL #include <iostream&g ...

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

    1.找出一个最长的回文子串,要求中间的值最大,然后向两侧递减. 2.判断条件改为:Ma[i+Mp[i]]==Ma[i-Mp[i]]&&Ma[i-Mp[i]]<=Ma[i-Mp[i ...

随机推荐

  1. MYSQL使用inner join 进行 查询/删除/修改示例

    代码如下: --查询 SELECT tp.tp_id, tp.tpmc, tp.leveid, tp.tpdz, tp.jgm, tp.scsj, tp.pbzyid, tp.ksbfsj, tp.j ...

  2. 还在为开发APP发愁? 这里就有现成通用的代码!

    1.开源控件 1)首页: 1.1)首先是下拉刷新数据的 SwipeRefreshLayout 地址:https://github.com/hanks-zyh/SwipeRefreshLayout 1. ...

  3. A nonrecursive list compacting algorithm

    A nonrecursive list compacting algorithm Each Erlang process has its own stack and heap which are al ...

  4. if return 和 if else

    最近看Node.js实战中,有一段代码是优化之前使用if else,优化之后是使用if return,我不知道if return是不是效率比if else高. 优化前: if(err){ handle ...

  5. 贞鱼传教&&贞鱼传教(数据加强版)

    http://acm.buaa.edu.cn/problem/1381/ 贞鱼传教[问题描述] 新的一年到来了,贞鱼哥决定到世界各地传授“贞教”,他想让“贞教”在2016年成为世界第四大宗教.说干就干 ...

  6. [RK3288]PMU配置(RK808)【转】

    本文转载自:http://www.javashuo.com/content/p-6398007.html 硬件原理 pmic 电路原理 平台概述 RK808 PWM 介绍 驱动分析 dts 驱动流程 ...

  7. dns服务器报错解决

    搭了个dns服务器,配置完毕老是报错,这里总结一下常见思路: ①关闭firewalld ②关闭selinux ③/var/named里面的配置文件所属用户组是否是root:named ④named.c ...

  8. oracle:os认证用户登录测试

        90%的情况下,我们使用的都是数据库认证用户登录oracle,但还存在使用OS认证用户登录oracle的情况: 下面就实验一下OS用户要登录oracle相关操作: 测试环境:oracle10. ...

  9. Linux 下WAS的java版本查看

    1.查找linux的详细版本号: A.cat /proc/version B.lsb_release -a(可以查出是否为redhat开发的) C.uname -a 2.Linux的java版本 A. ...

  10. cf 620C Pearls in a Row(贪心)

    d.有一串数字,要把这些数字分成若干连续的段,每段必须至少包含2个相同的数字,怎么分才能分的段数最多? 比如 是1 2 1 3 1 2 1 那么 答案是 21 34 7 即最多分在2段,第一段是1~3 ...