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: ...
随机推荐
- ie6下position:fixed定位问题
1. *html{ background-image:url(about:blank); background-attachment:fixed;}2.将需要用固定定位的元素中加上_position: ...
- CAD教程----圆的优化命令viewres
CAD软件为了节省内存加快打开图纸的速度,会在显示圆形的时候,用很粗燥的直线表示园,这时我们可以不节省内存,使用viewres将圆形完整的显示出来. 这个值设置的越大,圆越圆(好绕口!)
- NHibernate之旅(18):初探代码生成工具使用
本节内容 引入 代码生成工具 结语 引入 我们花了大量的篇幅介绍了相关NHibernate的知识.一直都是带着大家手动编写代码,首先创建数据库架构.然后编写持久化类和映射文件,最后编写数据操作方法.測 ...
- 命令模式之2 Invoker Vs. Client
当程序中直接编写下达命令的语句如new Cmd1().execute()时.一般会将调用者与客户类合二为一. 在GUI程序中.下达命令的语句通常包括在底层框架中.或者说底层框架包括了调用者.这时程序猿 ...
- 前端 自定义format函数
为字符串创建format方法,用于字符串格式化 {# 前端没有字符串占位符%s的替代方法,以下是自定义字符串替换的方法,以后前端拓展方法都可以使用下面的形式 #} String.prototype. ...
- POJ - 3257 Cow Roller Coaster (背包)
题目大意:要用N种材料建一条长为L的路,如今给出每种材料的长度w.起始地点x.发费c和耐久度f 问:在预算为B的情况下,建好这条路的最大耐久度是多少 解题思路:背包问题 dp[i][j]表示起始地点为 ...
- ContextMenu的使用具体解释
二话不说,先上图: 能够非常easy看到这是一个类似于Dialog悬浮在活动上的控件,它是由被注冊的view长按所触发的. 当然啦,也有其它的实现方式,这里就先介绍一下系统的ContextMenu:( ...
- MongodDB用GridFS方式存取文件
在实现GridFS方式前我先讲讲它的原理,为什么可以存大文件.驱动首先会在当前数据库创建两个集合:"fs.files"和"fs.chunks"集合,前者记录了文 ...
- 通过setSystemUiVisibility实现状态栏跟Activity之间的位置关系
曾经说到去除状态栏和标题栏总会用到动态代码的方式实现: getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN , Windo ...
- UVA 11426 - GCD - Extreme (II) 欧拉函数-数学
Given the value of N, you will have to find the value of G. The definition of G is given below:G =i< ...