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: ...
随机推荐
- 03springMVC注解式控制器开发
注解式控制器开发简介 注解式控制器开发HelloWorld HelloWorld的运行流程 处理器定义 REST简介 URL路径映射 数据绑定 不同的Model有相同的属性的处理 静态资源的处理 1 ...
- L - 还是畅通工程
L - 还是畅通工程 思路:水! #include<cstdio> #include<cstring> #include<iostream> #include& ...
- 继续过Hard题目.0209
http://www.cnblogs.com/charlesblc/p/6372971.html 继续过Hard模式的题目吧. # Title Editorial Acceptance Diffi ...
- linux入门基础——linux用户基础
这篇内容是linux用户基础,相关内容见linux改动username和ubuntu改动username和主机名. 用户.组 当我们使用linux时,须要以一个用户的身份登入,一个进程也须要以一个用户 ...
- CF 558C(Amr and Chemistry-构造法)
C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【Android 应用开发】Android 平台 HTTP网速測试 案例 API 分析
作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/25996817 工信部规定的网速測试标准 : 除普通网页測速 ...
- java 递归实现删除或查询指定目录下的全部文件
/** * 递归列举盘符下的全部文件的名称,如E:\HeartIsland * * @author HeartIsland * */ public class FileListDemo { /** * ...
- 【POJ 2942】Knights of the Round Table(双联通分量+染色判奇环)
[POJ 2942]Knights of the Round Table(双联通分量+染色判奇环) Time Limit: 7000MS Memory Limit: 65536K Total Su ...
- kaggle 中使用ipython
# pandas import pandas as pd from pandas import Series,DataFrame # numpy, matplotlib, seaborn import ...
- [SCOI 2008] 奖励关
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1076 [算法] f[i][S]表示当前第i次抛出宝物,目前集合为S,所能获得的最高分 ...