吉哥系列故事——完美队形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],吉哥希望从中挑出 ...
随机推荐
- mybatis0203 一对一查询 resultMap实现
resultType实现的时候先要确定po类(数据库类)满不满足要求,如果不满足就要自定义一个pojo类(工具类). resultMap提供一对一关联查询的映射和一对多关联查询映射,一对一映射思路:将 ...
- raft 分布式协议 -- mongodb
http://www.mongoing.com/presentations/webinar-raft-consensus-in-mongodb#rd
- one problem about Apple Keychain in use
解决方案 Add Security.framework, then rebuild. Sometimes I find I have to build clean and then rebuild. ...
- [转]allocWithZone 和 单例模式
一.问题起源 一切起源于Apple官方文档里面关于单例(Singleton)的示范代码:Creating a Singleton Instance. 主要的争议集中在下面这一段: ? 1 2 3 4 ...
- java String的比较,BOX装箱拆箱,以及面向对象的小代码
package cn.hncu.day2; public class StringDemo { public static void main(String[] args) { String str1 ...
- ubuntu常用文件搜索命令 分类: linux 学习笔记 ubuntu 2015-07-05 15:40 84人阅读 评论(0) 收藏
1.find find [搜索路径] [搜索关键字] 比如查找/test中文件名为t5.tmp的文件: 查找根目录下大于100M的文件 注意,这里的204800单位是块,1块=512字节 在根目录下查 ...
- Linux查看某个文件被哪些进程PID占用
比如查看test.sh这个文件被哪些进程占用,可以用: lsof | grep test.sh 或者 fuser -v test.sh
- (转)Spring 读书笔记-----使用Spring容器(一)
Spring有两个核心接口:BeanFactory和ApplicationContext,其中ApplicationContext是BeanFactory的子接口.他们都可代表Spring容器,Spr ...
- Tomcat-java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
好些天没弄java了,今天开MyEclipse,发现启动Tomcat的时候发错了,后来发现,报错如题. 解决方案是将 bin/tomcat-juli.jar 添加到add tomcat classpa ...
- maven中tomcat7-maven-plugin插件的使用
1.(挺清晰,但是我在项目上尝试没有成功) http://blog.csdn.net/yhhazr/article/details/7866501 2.(算是有一些详细的运行命令吧,例如自动打包命令或 ...