hdu5371 Hotaru's problem
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2189 Accepted Submission(s): 774
Let's define N-sequence, which is composed with three parts and satisfied with the following condition:
1. the first part is the same as the thrid part,
2. the first part and the second part are symmetrical.
for example, the sequence 2,3,4,4,3,2,2,3,4 is a N-sequence, which the first part 2,3,4 is the same as the thrid part 2,3,4, the first part 2,3,4 and the second part 4,3,2 are symmetrical.
Give you n positive intergers, your task is to find the largest continuous sub-sequence, which is N-sequence.
For each test case:
the first line of input contains a positive integer N(1<=N<=100000), the length of a given sequence
the second line includes N non-negative integers ,each interger is no larger than 109 ,
descripting a sequence.
We guarantee that the sum of all answers is less than 800000.
1
10
2 3 4 4 3 2 2 3 4 4
Case #1: 9这题能够用Manacher算法做。由于题目要找的是三段(第一段和第二段对称,第二段和第三段对称)。事实上就是两个连在一起的回文串,我们能够先用Manacher算法初始化各个点的p[i]值(即能够向右延伸的最大距离。包含本身,这时已经增加了-1取代算法中的'#',-2取代算法中的'$'),然后对于每一个i。枚举j(j属于1~p[i]-1),假设i+j-p[i+j]+1<=i,那么说明i。j能够分别作为第一、二段的点和第二、三段的点)。 这里有个优化,由于枚举时满足条件的仅仅有'#'(即'-1’),所以我们能够使i,j每次变化2.#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define maxn 100060
int a[maxn],b[2*maxn],p[2*maxn];
int main()
{
int n,m,i,j,T,mx,idx,maxx,num1=0;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
if(n<3){
printf("0\n");continue;
}
b[0]=-2;
b[1]=-1;
for(i=0;i<n;i++){
b[i*2+2]=a[i];
b[i*2+3]=-1;
}
n=2*n+2;mx=0;
for(i=0;i<n;i++){
if(i<mx){
p[i]=min(p[idx*2-i],mx-i);
}
else p[i]=1;
while(b[i-p[i]]==b[i+p[i]]){
p[i]++;
}
if(mx<i+p[i]){
mx=i+p[i];
idx=i;
}
}
maxx=0;
for(i=3;i<n;i+=2){
for(j=p[i]-1;j>=1;j-=2){
if(j<maxx)break;
if(i+j-p[i+j]+1<=i){
maxx=max(maxx,j);break;
}
} }
num1++;
printf("Case #%d: ",num1);
printf("%d\n",maxx/2*3);
}
return 0;
}
hdu5371 Hotaru's problem的更多相关文章
- Hotaru's problem(hdu5371+Manacher)多校7
Hotaru's problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 【HDOJ 5371】 Hotaru's problem
[HDOJ 5371] Hotaru's problem Manacher算法+穷举/set Manacher算法一好文:http://blog.csdn.net/yzl_rex/article/de ...
- hdu 5371 Hotaru's problem【manacher】
题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=5371 题意: 给出一个长度为n的串,要求找出一条最长连续子串.这个子串要满足:1:能够平均分成三段 ...
- HDU 5371 Hotaru's problem(Manacher算法+贪心)
manacher算法详见 http://blog.csdn.net/u014664226/article/details/47428293 题意:给一个序列,让求其最大子序列,这个子序列由三段组成, ...
- HDU 5371(2015多校7)-Hotaru's problem(Manacher算法求回文串)
题目地址:HDU 5371 题意:给你一个具有n个元素的整数序列,问你是否存在这样一个子序列.该子序列分为三部分,第一部分与第三部分同样,第一部分与第二部分对称.假设存在求最长的符合这样的条件的序列. ...
- HDU 5371 (2015多校联合训练赛第七场1003)Hotaru's problem(manacher+二分/枚举)
pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序 ...
- [2015hdu多校联赛补题]hdu5371 Hotaru's problem
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5371 题意:把一个数字串A翻过来(abc翻过来为cba)的操作为-A,我们称A-AA这样的串为N-se ...
- HDU5371 Hotaru's problem
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- hdu5371 Hotaru's problem
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission ...
随机推荐
- C#中的常量、类型推断和作用域
一.常量 常量是其值在使用过程中不会发生变化的变量.在声明和初始化变量时,在变量前面家关键字const,就可以把该变量指定为一个常量: const int a=100;//a的值将不可以改变 常量的特 ...
- Linux修改ssh端口,减少暴力破解
版本centos7 注意:操作时请勿断开当前的ssh连接,以免发生情况登陆不了. 1.修改的是 /etc/ssh/sshd_config 文件 打开文件之后会发现Port是注释掉的,默认为22 ...
- VS2010 好用的javascript扩展工具
工具1) JScript Editor Extensions 折叠代码 下载地址: JScript Editor Extensions 工具2) Javascript parser 以树形方式查的代码 ...
- 恩智浦Freescale Cortex-A9 迅为IMX6开发板平台初体验
iTOP-i.MX6 开发板预装 Android4.4 系统,采用 9.7 寸(或者 7 寸或者 4.3 寸)IPS 屏 幕,至少 5 点以上触控,操作流畅,无论是高清视频.游戏等都会有上佳的表现,实 ...
- CREATE DATABASE - 创建新数据库
SYNOPSIS CREATE DATABASE name [ [ WITH ] [ OWNER [=] dbowner ] [ LOCATION [=] 'dbpath' ] [ TEMPLATE ...
- vs2019装了WDK后,编译其他vc工程,提示无法打开文件"msvcprtd.lib"
今天安装了vs2019,而后又安装了wdk,随便写了一个控制台测试程序,居然报错.网上也查了一圈,也没有得到解决.报错内容如下: MSB8038:已启用Spectre缓解,但找不到Spectre缓解库 ...
- js 上传图片、压缩、旋转
亲测 <!doctype html> <html> <head> <meta charset="utf-8"> <title& ...
- pycharm激活2018
因为我的是Windows,所以这篇文章只针对Windows系统. 1.将“0.0.0.0 account.jetbrains.com”中的内容添加到hosts文件中,hosts路径为:C:\Windo ...
- extjs动态添加列
可以根据日期,动态的插入一列 controller层: StdDayWordQuery:function(btn,event){ var form=Ext.getCmp('queryFormSDW') ...
- luogu4388 付公主的矩形
题面: 为了排解心中的怒气,她造了大量的稻草人来发泄.每天付公主都会把一些稻草人摆成一个R∗C的矩形,矩形的每个方格上都有一个稻草人.然后她站在这个矩形的左上角,向矩形的右下角射箭.付公主的箭术过人, ...