HDU 4513 吉哥系列故事——完美队形II
变形的Manacher算法,在扩展的时候要加入限制条件,满足题目中说的从左到中间身高不减。
其他地方倒是没有什么改动。。
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ;
int n;
int a1[maxn], a2[maxn * ], p[maxn * ]; void Init(void)
{
int id, mx = , j = ;
a2[] = -, a2[] = ;
for(int i = ; i < n; ++i)
{
a2[j++] = a1[i];
a2[j++] = ;
}
} void Manacher(int a[])
{
int mx = , id;
p[] = ;
for(int i = ; i < (n+)*; ++i)
{
if(mx > i)
p[i] = min(p[id*-i], mx-i);
else
p[i] = ;
while(a[i+p[i]] == a[i-p[i]])
{
if(a[i-p[i]])
{
if(a[i-p[i]] <= a[i-p[i]+])
++p[i];
else
break;
}
else
++p[i];
}
if(mx < i + p[i])
{
mx = i + p[i];
id = i;
}
}
} void getans(void)
{
int ans = ;
for(int i = ; i < (n+)*; ++i)
ans = max(ans, p[i] - );
printf("%d\n", ans);
} int main(void)
{
#ifdef LOCAL
freopen("4513in.txt", "r", stdin);
#endif int T;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i = ; i < n; ++i)
scanf("%d", &a1[i]);
Init();
Manacher(a2);
getans();
}
return ;
}
代码君
HDU 4513 吉哥系列故事——完美队形II的更多相关文章
- HDU 4513 吉哥系列故事――完美队形II
http://acm.hdu.edu.cn/showproblem.php?pid=4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) ...
- HDU 4513 吉哥系列故事――完美队形II(Manacher)
题目链接:cid=70325#problem/V">[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher V - 吉哥系列故事――完美队形I ...
- HDU 4513 吉哥系列故事——完美队形II manacher
吉哥系列故事——完美队形II Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希 ...
- hdu 4513 吉哥系列故事——完美队形II (manachar算法)
吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) P ...
- HDU 4513 吉哥系列故事——完美队形II(Manacher)
Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成 ...
- HDU 4513 吉哥系列故事——完美队形II (Manacher变形)
题意:假设有n个人按顺序的身高分别是h[1], h[2] ... h[n],从中挑出一些人形成一个新的队形,新的队形若满足以下要求,则就是新的完美队形: 1.连续的 2.形成回文串 3.从左到中间那 ...
- HDU 4513 吉哥系列故事——完美队形II( Manacher变形 )
链接:传送门 思路:根据完美队形的定义,可以得知,完美队形实质上是 回文串 + 序列出现峰,因为是在回文串中再次增加了一个要求,所以可以对 Manacher 进行改造,改造的部分应该为暴力匹配的循环 ...
- Hdu 4513 吉哥系列故事——完美队形II (manacher变形)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4513 题目描述: 打完题目描述了,点开题目,发现题目是中文,orz.jpg.果断又删掉了,习惯真可怕 ...
- HDU - 4513 吉哥系列故事――完美队形II(manacher)
1.找出一个最长的回文子串,要求中间的值最大,然后向两侧递减. 2.判断条件改为:Ma[i+Mp[i]]==Ma[i-Mp[i]]&&Ma[i-Mp[i]]<=Ma[i-Mp[i ...
随机推荐
- 关于JS中的constructor与prototype
======================================================================== 在学习JS的面向对象过程中,一直对constructo ...
- LA 3350
The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site of the ACM ...
- javascript的Function 和其 Arguments
http://shengren-wang.iteye.com/blog/1343256 javascript的Function属性:1.Arguments对象2.caller 对调用单前函数的Func ...
- Windows Server2008+IIS7部署网站的日期格式问题
最近部署一个ASP网站,发现网站的某个功能上的日历在原来的服务器上访问时是会根据特定日期来对该日进行加粗加红显示的,但部署到我公司机房的win2008服务器上访问时却没有这效果了. 于是通过本地部署, ...
- spring 主题使用详解[转]
在common_include_v2.jsp文件中,spring主题的使用: <link href="${staticPath }/<spring:theme code='sty ...
- 编程实现LINUX下目录的层层遍历
/************************************************************************* > File Name: treedir.c ...
- 关于如何使用Navicat(11.1.13) for MySQL如何创建存储过程
1.ƒ()函数(右键)→新建函数(左键)→过程(选择) 2.会遇到的问题 问题一:因为sql语句默认以;为结束符,所以应该修改结束符,但是这在Navicat(11.1.13) for MySQL中是不 ...
- 【Apache运维基础(4)】Apache的Rewrite攻略(1)
简述 Rewirte主要的功能就是实现URL的跳转,它的正则表达式是基于Perl语言.可基于服务器级的(httpd.conf)和目录级的 (.htaccess)两种方式.如果要想用到rewrite模块 ...
- Android核心分析之十九电话系统之GSMCallTacker
GSMCallTracker在本质上是一个Handler.<IGNORE_JS_OP> 1.jpg (1.52 KB, 下载次数: 1) 下载附件 保存到相册 2012-3-22 11: ...
- 自己写的中间层..基于通讯组件 RTC
273265088 我用原生Listbox与你的组件组合...创造了奇迹..搞了一个非常复杂的 UI .. 每个item高度 包括里面的元素 以及事件都是动态的搞了好几个小时感觉UI 非常完美比客户要 ...