Hotaru's problem

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

Total Submission(s): 2274    Accepted Submission(s): 795

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
 

关于manacher算法,链接:>>manacher<<

转载请注明出处:寻找&星空の孩子

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5371

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define maxn 100010*2
const int mm=1e9+7;
int P[maxn];
//(p.s. 能够看出。P[i]-1正好是原字符串中回文串的总长度)
int s1[maxn];
int s2[maxn];
int n;
int min( int x, int y )//Wa,没加这个。。。
{
return x < y ? x : y;
} void manacher(int* s)
{
int i,id=0,mx=0;
P[0]=0;
for(i=1;i<=2*n+1;i++)
{
if(mx > i)
P[i] = min(P[2*id-i],mx-i);
else
P[i] = 1;
while(s[i+P[i]]==s[i-P[i]] )
{
P[i]++;
}
if(mx < P[i] + i)
{
mx = P[i] + i;
id = i;
}
}
} void init(int n)
{
int i, j = 2;
s2[0] =-1, s2[1] = -2; for(i=0;i<n;i++)
{
s2[j++] = s1[i];
s2[j++] = -2;
}
s2[j]=-3;
} int main()
{
// printf("%d\n",mm);
int T,ca=1;
scanf("%d",&T);
while(ca<=T)
{
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&s1[i]);
init(n);
manacher(s2);
int ans=0;
for(int i=1;i<=2*n+1;i+=2)
{
// printf("i=%d\tP=%d\n",i,P[i]); for(int j=P[i]+i-1;j-i>ans;j-=2)
{
if(j-i+1<=P[j])
{
ans=max(ans,j-i);
break;//坑
}
} }
printf("Case #%d: %d\n",ca++,ans/2*3);
}
return 0;
}
/*
2
10
2 3 4 4 3 2 2 3 4 4
7
1 2 3 2 1 2 3
*/

Hotaru&#39;s problem(hdu5371+Manacher)多校7的更多相关文章

  1. HDU 5371 Hotaru&#39;s problem(Manacher算法+贪心)

    manacher算法详见 http://blog.csdn.net/u014664226/article/details/47428293 题意:给一个序列,让求其最大子序列,这个子序列由三段组成, ...

  2. hdu 5371 Hotaru&#39;s problem【manacher】

    题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=5371 题意: 给出一个长度为n的串,要求找出一条最长连续子串.这个子串要满足:1:能够平均分成三段 ...

  3. HDU 5371(2015多校7)-Hotaru&#39;s problem(Manacher算法求回文串)

    题目地址:HDU 5371 题意:给你一个具有n个元素的整数序列,问你是否存在这样一个子序列.该子序列分为三部分,第一部分与第三部分同样,第一部分与第二部分对称.假设存在求最长的符合这样的条件的序列. ...

  4. HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&#39;s problem(manacher+二分/枚举)

    pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序 ...

  5. hdu5371 Hotaru&#39;s problem

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

  6. 【HDOJ 5371】 Hotaru&#39;s problem

    [HDOJ 5371] Hotaru's problem Manacher算法+穷举/set Manacher算法一好文:http://blog.csdn.net/yzl_rex/article/de ...

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

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

  8. HDU 5371 Hotaru's problem (Manacher,回文串)

    题意:给一个序列,找出1个连续子序列,将其平分成前,中,后等长的3段子序列,要求[前]和[中]是回文,[中]和[后]是回文.求3段最长为多少?由于平分的关系,所以答案应该是3的倍数. 思路:先Mana ...

  9. hdu5371Hotaru&#39;s problem manacher算法

    //给一个序列.让求其最大子序列 //这个序列由三段组成.第一段和第二段对称,第一段和第三段一样 //manacher算法求得p[i] //枚举第二段的起点和长度,得到结果 #include<c ...

随机推荐

  1. elasticsearch实例讲解增删改查

    1.首先弄明白四个概念 elasticsearch 关系型数据库 index 数据库 type 表 document 行 field 字段 如果刚一开始理解比较困难,那你就在心中默念100遍,10遍也 ...

  2. [转载] 使用Kettle进行数据迁移(ETL)

    由于开发新的系统,需要将之前一个老的C/S应用的数据按照新的数据设计导入到新库中.此过程可能涉及到表结构不一致.大数据量(千万级,甚至上亿)等情况,包括异构数据的抽取.清洗等等工作.部分复杂的工作需要 ...

  3. windows下git命令的使用

    一.写在前面 关于git,出于自己的爱好,前段时间玩了一下,也自己上网查了一下资料,现简单记录一下,以备查看. 当然,本文并不是介绍配置git服务器的文章,而是以github服务器作为git的远程仓库 ...

  4. Tasker to answer incoming call by pressing power button

    nowadays, the smartphone is getting bigger in size, eg. samsung galaxy note and note 2, sorta big in ...

  5. 白光LED驱动方案的选择 TPS61043

    所有专为驱动白光LED而设计的IC都提供恒定电流夕其中尽大多数是基于电感或电荷泵的解决方案9这两种解决方案各有其优缺点. 电荷泵解决方案也称为开关电容器解决方案,利用分离电容器将电源从输进端传送至输出 ...

  6. 使用CSS3的@media来实现网页自适应

    如今,电脑显示器的屏幕分辨率向越来越大发展,而手机等移动设备终端的分辨率却不可能大到哪里去.越来越多的网站,开始让自己的页面自适合各种分辨率,在小分辨率下显示基本的内容,在大分辨率下显示全部功能,甚至 ...

  7. 十大开源ERP点评 献给深水区的中小企业和CIO们

    原文地址:http://www.oschina.net/news/58437/top-10-erp-software 如今,企业资源规划(ERP)和客户关系管理(CRM)系统的必要性已经被各种组织和企 ...

  8. [翻译] ClockView 时钟

    ClockView 时钟 https://github.com/nacho4d/ClockView Overview ClockView is s simple class that will sim ...

  9. java使用POI获取sheet、行数、列数

    FileInputStream inp = new FileInputStream("E:\\WEIAN.xls"); HSSFWorkbook wb = new HSSFWork ...

  10. Python3.6学习笔记(五)

    网络编程 网络程序出现的比互联网要早很多,实现方式主要依靠网络上不同主机间进程的通信,通信协议最重要的是TCP/IP协议.在这两个协议基础上还有很多更高级的协议,包括HTTP.SMTP等.要进行两个主 ...