HDU 5371——Hotaru's problem——————【manacher处理回文】
Hotaru's problem
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1765 Accepted Submission(s): 635
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;
#define min(a,b) ((a)<(b)?(a):(b))
const int maxn=1e6;
int a[maxn],p[maxn];
void Manacher(int n){
a[0]=-2;a[n+1]=-1;a[n+2]=-3;
int mx=0,id=0;
for(int i=1;i<=n+1;i++){ //需要处理到n+1
if(i<mx){
p[i]=min(p[id*2-i],mx-i); //这里写的时候写成mx-id,SB了。
}else{
p[i]=1;
}
for(;a[i+p[i]]==a[i-p[i]];++p[i]); //-2,-3防越界
if(i+p[i]>mx){
mx=p[i]+i;
id=i;
}
}
for(int i=1;i<=n+1;++i){
--p[i];
}
}
int main(){
// freopen("1003.in","r",stdin);
// freopen("OUTTTT.txt","w",stdout);
int t,n,cnt=0;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=2*n;i+=2){
a[i]=-1;
scanf("%d",&a[i+1]);
} Manacher(2*n);
int maxv=0,j;
for(int i=1;i<=2*n;i+=2){ //2*n
for(j=i+p[i];j-maxv>i;j-=2){ //逆序枚举。manacher算法保证j<=2*n+1
if(j-p[j]<=i){
maxv=j-i;
break;
}
}
}
maxv=3*(maxv/2);
printf("Case #%d: %d\n",++cnt,maxv);
}
return 0;
}
HDU 5371——Hotaru's problem——————【manacher处理回文】的更多相关文章
- Hdu 5371 Hotaru's problem (manacher+枚举)
题目链接: Hdu 5371 Hotaru's problem 题目描述: 给出一个字符串N,要求找出一条N的最长连续子串.这个子串要满足:1:可以平均分成三段,2:第一段和第三段相等,3:第一段和第 ...
- HDU 5371 Hotaru's problem Manacher+尺取法
题意:给你一个序列,求最长的两段回文子串,要求他们共用中间的一半. 思路:利用Manacher求出p[i]表示的当前位置的最长回文串长度,然后把每一个长度大于等于2的回文串的左区间和右区间分别放到两个 ...
- HDU 5371 Hotaru's problem (Manacher,回文串)
题意:给一个序列,找出1个连续子序列,将其平分成前,中,后等长的3段子序列,要求[前]和[中]是回文,[中]和[后]是回文.求3段最长为多少?由于平分的关系,所以答案应该是3的倍数. 思路:先Mana ...
- 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) ...
- HDU 5340——Three Palindromes——————【manacher处理回文串】
Three Palindromes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- Manacher HDOJ 5371 Hotaru's problem
题目传送门 /* 题意:求形如(2 3 4) (4 3 2) (2 3 4)的最长长度,即两个重叠一半的回文串 Manacher:比赛看到这题还以为套个模板就行了,因为BC上有道类似的题,自己又学过M ...
- Manacher以及回文树算法学习
Manacher以及回文树算法学习 一.Manacher 关于\(Manacher\),这篇博客 讲的很清楚. 大致总结一下 为了将长度为奇数的回文串和长度为偶数的回文串一起考虑,需要在原字符串中插入 ...
- 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)
[SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...
- hdu 5371 Hotaru's problem【manacher】
题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=5371 题意: 给出一个长度为n的串,要求找出一条最长连续子串.这个子串要满足:1:能够平均分成三段 ...
随机推荐
- win10下安装配置mysql-8.0.13--实战可用
1.下载mysql-8.0.13安装包 1 https://dev.mysql.com/downloads/mysql/ 选择zip安装包下载就好. 2.解压到你要安装的目录 3.创建my.ini配置 ...
- fiddler扩展模拟弱网络环境设置
今天在qq群中有人问到怎么模拟app弱网络环境,我查了下资料,记得之前做测试的时候是设置fiddler断点,app请求后止于fiddler断点,app一直拿不到响应结果就应该要给出网络请求失败的提示, ...
- fopen_s()
原型:errno_t fopen_s( FILE** pFile, const char *filename, const char *mode ); 例子: char *filePath=&q ...
- 「BZOJ 3994」「SDOI 2015」约数个数和「莫比乌斯反演」
题意 设\(d(x)\)为\(x\)的约数个数,求\(\sum_{i=1}^{n}\sum_{j=1}^{m}d(ij)\). 题解 首先证个公式: \[d(ij) = \sum_{x|i}\sum_ ...
- 502. IPO
Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Cap ...
- ACM 离散化处理
使用STL算法离散化: 思路:先排序,再删除重复元素,然后就是索引元素离散化后对应的值. 1. unique(): 头文件为algorithm unique的作用是“去掉”容器中相邻元素的重复元 ...
- codevs1068(dp)
题目链接: http://codevs.cn/problem/1068/ 题意: 中文题诶~ 思路: dp 用 dp[i][j][k][l] 表示取 i 个 1, j 个 2, k 个 3, l 个 ...
- 【三支火把】--- 关于UEFI&PCD的总结介绍
1个人理解 个人理解PCD基本等同于Token,应当算是一种描述性语言,按照规定书写好PCD的配置档,在编译的过程中,会根据你的配置生成同等含义的C文档,而在C文档中对应会出现相应的define或者变 ...
- Glassfish Password Alias
https://docs.oracle.com/cd/E19798-01/821-1751/ghgqc/index.html
- swift -- 单例+ lazy懒加载 + 第三方库
//工具类单例 static let goods : NHGoods = { let good = NHGoods() return good }() //懒加载 lazy var registerB ...