吉哥系列故事——完美队形II
hdu4513:http://acm.hdu.edu.cn/showproblem.php?pid=4513
题意:给以一个序列,然后让你求一个最长回文序列的长度,这个序列的从左到最中间那个数是不降的,从中间那里向右边的话是不增的。
题解:用Manacher搞定,直接套模板还不行,还要做一些判断。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define M 800050
using namespace std;
int str1[M],str[M*];
int rad[M];
void Manacher(int *rad, int *str,int n){
int i,mx=,id;
for(int i=;i<n;i++){//下标从1开始
if(mx>i){
rad[i]=min(rad[*id-i],mx-i);
}
else rad[i]=;
while(str[i+rad[i]]==str[i-rad[i]]){
if(str[i+rad[i]]!=){
if(str[i+rad[i]]<=str[i+rad[i]-])
rad[i]++;
else
break;
}
else
rad[i]++;
}
if(rad[i]+i>mx){
mx=rad[i]+i;
id=i;
}
}
}
int main(){
int ans,cas;
scanf("%d",&cas);
while(cas--){
int nn;
scanf("%d",&nn);
for(int i=;i<nn;i++)
scanf("%d",&str1[i]);
memset(str,,sizeof(str));
int n=nn*+;
str[]=;
memset(rad,,sizeof(rad));
for(int i=;i<=nn;i++){
str[*i+]=;
str[*i+]=str1[i];
}
Manacher(rad,str,n);
ans=;
for(int i=;i<n;i++)
ans=max(ans,rad[i]);
printf("%d\n",ans-);
}
return ;
}
吉哥系列故事——完美队形II的更多相关文章
- HDU 4513 吉哥系列故事——完美队形II manacher
吉哥系列故事——完美队形II Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希 ...
- hdu----(4513)吉哥系列故事——完美队形II(manacher(最长回文串算法))
吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)To ...
- (回文串 Manacher)吉哥系列故事——完美队形II -- hdu -- 4513
http://acm.hdu.edu.cn/showproblem.php?pid=4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) ...
- hdu 4513 吉哥系列故事——完美队形II (manachar算法)
吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) P ...
- HDU4513:吉哥系列故事——完美队形II(Manacher)
吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)To ...
- HDU 4513 吉哥系列故事――完美队形II(Manacher)
题目链接:cid=70325#problem/V">[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher V - 吉哥系列故事――完美队形I ...
- HDU4513 吉哥系列故事——完美队形II Manacher算法
题目链接:https://vjudge.net/problem/HDU-4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Me ...
- 吉哥系列故事——完美队形II(hdu4513+Manacher)
吉哥系列故事--完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) T ...
- HDU 4513 吉哥系列故事――完美队形II
http://acm.hdu.edu.cn/showproblem.php?pid=4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) ...
- 回文串---吉哥系列故事——完美队形II
HDU 4513 Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出 ...
随机推荐
- Apache Kafka: Next Generation Distributed Messaging System---reference
Introduction Apache Kafka is a distributed publish-subscribe messaging system. It was originally dev ...
- (转载)MyEclipse github
最近Git火得如日中天,而且速度体验和团队模式都很不错.手头正好有个学生实训项目,时间紧任务重,而且学校内网管理太紧,所以就想借助于Internet的分布式开发,因此想到了Github. ...
- SQL语句中"where 1=1"和"where 1=0"的作用
where 1=1; 这个条件始终为True,在不定数量查询条件情况下,1=1可以很方便的规范语句. 一.不用where 1=1 在多条件查询中的困扰 举个例子,如果您做查询页面,并且,可查询的选项有 ...
- javascript常用方法(慢慢整理)
获取类型:[object object],[object function],[object Undefined]等 Object.prototype.toString.apply(obj); 获取对 ...
- SOAP消息创建
看了SOAP消息分析之后,大家对soap消息应该有了一个初步的认识,那么怎样自己编写一个soap消息呢? 先来创建一个简单的soap消息: @Test public void test1(){ try ...
- Java基础知识强化之集合框架笔记63:Map集合之HashMap嵌套ArrayList
1. ArrayList集合嵌套HashMap集合并遍历. 需求:假设ArrayList集合的元素是HashMap.有3个.每一个HashMap集合的键和值都是字符串.元素我已经完成,请遍历. 结果: ...
- Java基础知识强化之IO流笔记29:BufferedOutputStream / BufferedInputStream(字节缓冲流)之BufferedInputStream读取数据
1. BufferedInputStream读取数据 BufferedInputStream构造方法,如下: 构造方法摘要 BufferedInputStream(InputStream in) ...
- iOS常见的几种延时执行的方法
1.performSelector [self performSelector:@selector(delayMethod) withObject:nil/*可传任意类型参数*/ afterDelay ...
- Microsoft Visual Studio Professional 2012 专业版 下载
记录(以下内容来自网络收集): 下载地址: https://www.microsoft.com/zh-cn/download/details.aspx?id=30682 直接iso连接下载址: htt ...
- WPF学习之资源-Resources
WPF学习之资源-Resources WPF通过资源来保存一些可以被重复利用的样式,对象定义以及一些传统的资源如二进制数据,图片等等,而在其支持上也更能体现出这些资源定义的优越性.比如通过Resour ...