Hotaru's problem

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3314    Accepted Submission(s): 1101

Problem Description
Hotaru Ichijou recently is addicated to math problems. Now she is playing with N-sequence.
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.

 
Input
There are multiple test cases. The first line of input contains an integer T(T<=20), indicating the number of test cases.

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.

 
Output
Each case contains only one line. Each line should start with “Case #i: ”,with i implying the case number, followed by a integer, the largest length of N-sequence.

We guarantee that the sum of all answers is less than 800000.

 
Sample Input
1
10
2 3 4 4 3 2 2 3 4 4
 
Sample Output
Case #1: 9
 
Author
UESTC
 
Source
 

//在manachar的基础上,枚举回文串的中心,再找第三部分。
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int read(){
register int x=;bool f=;
register char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return f?x:-x;
}
const int N=3e5+;
int n,ans,cas,l,T,s[N],S[N],p[N];
void manacher(){
int id=,mx=-;
for(int i=;i<l;i++){
if(id+mx>i) p[i]=min(p[id*-i],id+mx-i);
while(i-p[i]>=&&i+p[i]<=l&&S[i-p[i]]==S[i+p[i]]) p[i]++;
if(id+mx<i+p[i]) id=i,mx=p[i];
}
}
void init(){
l=;memset(p,,sizeof p);
for(int i=;i<n;i++) S[++l]=-,S[++l]=s[i];
S[++l]=-;
}
int main(){
for(T=read(),cas=;ans=,cas<=T;cas++){
n=read();
for(int i=;i<n;i++) s[i]=read();
init();manacher();
for(int i=;i<=n*+;i+=){
for(int j=i+p[i]-;j-i>ans;j-=){
if(j-i+<=p[j]){
ans=max(ans,j-i);
break;
}
}
}
printf("Case #%d: %d\n",cas,ans/*);
}
return ;
}

Hotaru's problem的更多相关文章

  1. [2015hdu多校联赛补题]hdu5371 Hotaru's problem

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5371 题意:把一个数字串A翻过来(abc翻过来为cba)的操作为-A,我们称A-AA这样的串为N-se ...

  2. HDU 5371——Hotaru's problem——————【manacher处理回文】

    Hotaru's problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  3. Hdu 5371 Hotaru's problem (manacher+枚举)

    题目链接: Hdu 5371 Hotaru's problem 题目描述: 给出一个字符串N,要求找出一条N的最长连续子串.这个子串要满足:1:可以平均分成三段,2:第一段和第三段相等,3:第一段和第 ...

  4. Manacher HDOJ 5371 Hotaru's problem

    题目传送门 /* 题意:求形如(2 3 4) (4 3 2) (2 3 4)的最长长度,即两个重叠一半的回文串 Manacher:比赛看到这题还以为套个模板就行了,因为BC上有道类似的题,自己又学过M ...

  5. 2015 Multi-University Training Contest 7 hdu 5371 Hotaru's problem

    Hotaru's problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  6. HDU5371 Hotaru's problem

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  7. hdu5371 Hotaru's problem

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission ...

  8. 回文串---Hotaru's problem

    HDU   5371 Description Hotaru Ichijou recently is addicated to math problems. Now she is playing wit ...

  9. Hotaru's problem(hdu 5371)

    题意:给出一个数字串,询问最长的子串,满足以下要求:将子串平均分为三部分,一三部分相等,一二部分对衬. /* 在manachar的基础上,枚举回文串的中心,再找第三部分. */ #include< ...

随机推荐

  1. Maven命令行使用:mvn clean package(打包)

    先把命令行切换到Maven项目的根目录,比如:/d/xxxwork/java/maven-test,然后执行命令:  mvn clean package 执行结果如下: [INFO] Scanning ...

  2. iOS隐私政策

    隐私政策 本应用尊重并保护所有使用服务用户的个人隐私权.为了给您提供更准确.更有个性化的服务,本应用会按照本隐私权政策的规定使用和披露您的个人信息.但本应用将以高度的勤勉.审慎义务对待这些信息.除本隐 ...

  3. 【特别推荐】小伙伴们惊呆了!8个超炫的 Web 效果

    CodePen 是一个在线的 HTML.CSS 和 JavaScript 代码编辑器,能够编写代码并即时预览效果.你在上面可以在线展示自己的作品,也可以看到其他人在网页中实现的各种令人惊奇的效果. 今 ...

  4. 本地部署arcgis by eclipse

    首次来博客园发帖,从本地部署arcgis api开始吧: 首先还是下载arcgis的api包开始,在中国区官网下载arcgis包: 1.http://support.esrichina.com.cn/ ...

  5. js中cookie的添加,删除,查询总结

    function addCookie(objName,objValue,objHours){//添加cookie var str = objName + "=" + escape( ...

  6. 阻止默认事件event.preventDefault();

    阻止浏览器默认事件.什么是默认事件,例如浏览器默认右键菜单.a标签默认连接跳转...,如何阻止呢? Firefox中,event必须作为参数传入.  IE中,event是window对象的属性. ev ...

  7. CoreGraphics-基本图形绘制-直线、三角形、矩形、椭圆形、弧形

    框架:CoreGraphics 步骤: 1."获取"图形上下文     let cxtRef = UIGraphicsGetCurrentContext()! 2.添加路径 3.渲 ...

  8. windows下安装web服务器

    有条件下还是在linux下部署.window上真心问题挺多的. 推荐安装Visual-NMP,轻量级.组件升级方面等. Nginx绑定IPv4和IPv6的方法 listen 80; listen [: ...

  9. log4j配置

    log4j.rootCategory=DEBUG , R, D,stdout # Console log4j.appender.stdout=org.apache.log4j.ConsoleAppen ...

  10. OC #import和@class的用法和区别

    OC #import和@class的用法和区别 import会包含这个类的所有信息,包括实体变量和方法,而@class只是告诉编译器,其后面声明的名称是类的名称,至于这些类是如何定义的,暂时不用考虑, ...