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. MongoDb gridfs-ngnix文件存储方案

          在各类系统应用服务端开发中,我们经常会遇到文件存储的问题. 常见的磁盘文件系统,DBMS传统文件流存储.今天我们看一下基于NoSQL数据库MongoDb的存储方案.笔者环境 以CentOS ...

  2. jQuery切换网页皮肤保存到Cookie实例

    效果体验:http://keleyi.com/keleyi/phtml/jqtexiao/25.htm 以下是源代码: <!DOCTYPE html PUBLIC "-//W3C//D ...

  3. javascript中的一些核心知识点以及需要注意的地方

    前言 近期杂事甚多,这些事情的积累对知识体系的提升有好处,但是却不能整理出来,也整理不出来 比如说我最近研究的Hybrid在线联调方案便过于依赖于业务,就算分享也不会有人读懂,若是抽一点来分享又意义不 ...

  4. tomcat远程调试javaweb

    当把一个本地项目部署到远程服务器后有可能出现意想不到错误,这个时候通过远程调试能够更清楚的找到bug所在位置. 目前百度tomcat绝大多数方法都是在startup.sh或者catalina.sh增加 ...

  5. mfc学习之路--如何删除通过控件新增的变量

    刚刚学校mfc的人都会遇到这样一个问题(比如我),在照做书做一个mfc程序,给控件新增变量时变量类型错了,但是变量名对了,然后想要加个正确的时候提示"已经存在该对象",然后就傻了, ...

  6. jQuery对表单、表格的操作及更多应用

    <head> <style type="text/css"> .even {     background-color: #fff38f;/*偶数行样式*/ ...

  7. 实现bootstrap布局的input输入框中的图标点击功能

    使用bootstrap布局可以在input的输入框中添加譬如登录名输入框中的一键清除图标和密码输入框中显示密码的小眼睛图标.如下图: 但是在将图标放入input输入框中,这些小图标是无法获得点击事件的 ...

  8. VS2010中整理代码快捷键

    快捷键:Ctrl+A Ctrl+K Ctrl+F的三个的组合2015-11-08

  9. Android自定义对话框

    在android中有自带的对话框,为了美观,很多开发者会使用自定义对话框,如下图: 点击“弹出自定义对话框按钮后”显示如图效果. 首先要自己定义一个xml文件定义自己对话框的样式: <?xml ...

  10. idea使用优化常用快捷键设置

    1. 界面美观 1.1. 主题 1.2. 改Project面板大小 2. 快捷键 2.1智能提示 2.2常用快捷键 3.编辑器调整 3.1 代码提示忽略大小写 3.2 显示行号 3.3 优化自动导入 ...