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)
Total Submission(s): 907 Accepted Submission(s): 322
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.
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int s[maxn],p[maxn];
int manacher(int n) {
int id = ,maxlen = ;
s[] = -;
for(int i = n; i >= ; --i) {
s[i + i + ] = s[i];
s[i + i + ] = ;
}
n = (n<<|);
for(int i = ; i < n; ++i) {
if(p[id] + id > i) p[i] = min(p[*id-i],p[id]+id-i);
else p[i] = ;
while(s[i-p[i]] == s[i+p[i]]) ++p[i];
if(id + p[id] < i + p[i]) id = i;
if(maxlen < p[i]) maxlen = p[i];
}
return maxlen - ;
}
char *ch, *ch1, buf[*+], buf1[*+];
void read(int &x) {
for (++ch; *ch <= ; ++ch);
for (x = ; '' <= *ch; ch++) x = x * + *ch - '';
}
int main() {
int kase,n,cs = ;
ch = buf - ;
ch1 = buf1 - ;
fread(buf, , * * , stdin);
read(kase);
while(kase--) {
read(n);
for(int i = ; i < n; ++i)
read(s[i]);
manacher(n);
int ret = ;
n = (n<<|);
for(int i = ; i < n; i += ) {
if(p[i] - > ret) {
int r = p[i] + ;
while(r > ret && p[i + r] < r) --r;
if(ret < r) ret = r;
}
}
printf("Case #%d: %d\n",cs++,(ret>>)*);
}
return ;
}
/*
1
11
1 1 2 1 1 2 1 1 2 1 1
*/
2015 Multi-University Training Contest 7 hdu 5371 Hotaru's problem的更多相关文章
- Hdu 5371 Hotaru's problem (manacher+枚举)
题目链接: Hdu 5371 Hotaru's problem 题目描述: 给出一个字符串N,要求找出一条N的最长连续子串.这个子串要满足:1:可以平均分成三段,2:第一段和第三段相等,3:第一段和第 ...
- 2015 Multi-University Training Contest 7 hdu 5373 The shortest problem
The shortest problem Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDU 5371 Hotaru's problem (Manacher,回文串)
题意:给一个序列,找出1个连续子序列,将其平分成前,中,后等长的3段子序列,要求[前]和[中]是回文,[中]和[后]是回文.求3段最长为多少?由于平分的关系,所以答案应该是3的倍数. 思路:先Mana ...
- HDU 5371——Hotaru's problem——————【manacher处理回文】
Hotaru's problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5371 Hotaru's problem Manacher+尺取法
题意:给你一个序列,求最长的两段回文子串,要求他们共用中间的一半. 思路:利用Manacher求出p[i]表示的当前位置的最长回文串长度,然后把每一个长度大于等于2的回文串的左区间和右区间分别放到两个 ...
- 2019 Multi-University Training Contest 2: 1010 Just Skip The Problem 自闭记
2019 Multi-University Training Contest 2: 1010 Just Skip The Problem 自闭记 题意 多测.每次给你一个数\(n\),你可以同时问无数 ...
- Manacher HDOJ 5371 Hotaru's problem
题目传送门 /* 题意:求形如(2 3 4) (4 3 2) (2 3 4)的最长长度,即两个重叠一半的回文串 Manacher:比赛看到这题还以为套个模板就行了,因为BC上有道类似的题,自己又学过M ...
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
随机推荐
- js cookie 设置
(function () { function getCookie(name) { var start = document.cookie.indexOf(name + "="); ...
- pandas深入理解
Pandas是一个Python库,旨在通过“标记”和“关系”数据以完成数据整理工作,库中有两个主要的数据结构Series和DataFrame In [1]: import numpy as np In ...
- 基于Linux环境Tomcat-MySQL的server搭建
在开发日趋激烈的今天.我们可不能再仅仅会编码了.这样搞不好.就成了一辈子的码奴!所以这里简单的分享一下server的搭建,因为Linux的安全性等一切因素让它成为了server平台的首选环境!今天跟大 ...
- [寒江孤叶丶的Cocos2d-x之旅_33]RichTextEx一款通过HTML标签控制文字样式的富文本控件
RichTextEx一款通过HTML标签控制文字样式的富文本控件 原创文章,欢迎转载.转载请注明:文章来自[寒江孤叶丶的Cocos2d-x之旅系列] 博客地址:http://blog.csdn.net ...
- bzoj3713: [PA2014]Iloczyn(乱搞)
3713: [PA2014]Iloczyn 题目:传送门 题解: 随手一发水题x2 直接离线啊,斐波那契到了第五十个就炒鸡大了 代码: #include<cstdio> #include& ...
- Ubuntu14.04下初步使用MongoDB
不多说,直接上干货! Ubuntu14.04下Mongodb(在线安装方式|apt-get)安装部署步骤(图文详解)(博主推荐) shell命令模式 输入mongo进入shell命令模式,默认连接的数 ...
- js面向对象概念解析
ECMAScript有两种开发模式: 1.函数式(过程化) 2.面向对象(OOP). 面向对象的语言有一个标志,那就是类的概念,而通过类可以创建任意多个具有相同属性和方法的对象.但是,ECMAScri ...
- signature验证/salt验证/token验证的作用
1.salt验证: salt是随机生成的一串字符,salt验证的作用是将生成的salt与加密的密码密文拼接后再次加密存储 这样可以是存储在数据库中的密码更加安全 2.signature验证: I.将 ...
- performSelector与objc_msgSend
- perform:(SEL)aSelector { if (aSelector) return objc_msgSend(self, aSelector); else return [self er ...
- Java用freemarker导出Word 文档
1.用Microsoft Office Word打开word原件: 2.把需要动态修改的内容替换成***,如果有图片,尽量选择较小的图片几十K左右,并调整好位置: 3.另存为,选择保存类型Word 2 ...