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: ...
随机推荐
- HDU5979 Convex
/* HDU5979 Convex http://acm.hdu.edu.cn/showproblem.php?pid=5979 计算几何 三角形面积公式 * * */ #include <cs ...
- nodejs-Module
nodejs的打包程序 模块:实现特定功能的文件 1.通过require引入模块 2.模块中的功能(变量,函数),通过赋给exports对象的某个属性提供给调用者使用 1 2 function sum ...
- 移动端js手指滑动事件初体验
今天在公司遇到做一个移动端手指滑动的效果,刚開始用了swiper.js插件发现效果不好(文字存在模糊效果).后来查了一些资料,自己手写了一个使用原生js写的滑动效果. 以下直接上代码: <!do ...
- 在 Eclipse 中使用 C++
安装 安装Eclipse Eclipse下载页 能够选择Eclipse IDE for C/C++ Developers(内置CDT插件) 也能够选择安装其它版本号之后再安装CDT插件. 安装CDT插 ...
- Android之弹出菜单框【注冊上下文菜单】
注冊上下文菜单:(长按弹出一个菜单) 第一种创建方法(与长按事件结合): public class MainActivity extends Activity { private TextView u ...
- centos cmake 升级
本以为升级cmake很简单 下载了最新的(3.15),./configure 没问题 make的时候,提示 openssl.c: undefined symbol openssl, openssl-d ...
- block的一些注意事项
1,定义block时是可以同时进行赋值的 2,block中是代码块,就是里面写的是语句,需要加分号 3,在block中,允许有多条语句 4,在带有参数的block中,声明部分参数名可以省略,但是建议写
- SQL Server 分割字符串转列
CREATE FUNCTION dbo.sf_DS_SplitNVarchar ( @strValues nvarchar(4000) ) RETURNS @tblStrList TABLE (id ...
- layui序章
layui,layer,laydate关系图,layer和laydate作为layui的独立模块存在 下载地址:layer.layui.com
- JavaScript设计模式学习——builder pattern(建造者模式)
个人理解的应用场景 举个例子,比如想要创建各种类型的车的实例,车的类型有很多种,但创建每种类型车的接口定义可能是一样的,就用到了此模式 相关概念的通俗解释 上述例子中接口的定义叫builder 接口到 ...