Hotaru's problem(hdu5371+Manacher)多校7
Hotaru's problem
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2274 Accepted Submission(s): 795
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.
1
10
2 3 4 4 3 2 2 3 4 4
Case #1: 9
关于manacher算法,链接:>>manacher<<
转载请注明出处:寻找&星空の孩子
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5371
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define maxn 100010*2
const int mm=1e9+7;
int P[maxn];
//(p.s. 能够看出。P[i]-1正好是原字符串中回文串的总长度)
int s1[maxn];
int s2[maxn];
int n;
int min( int x, int y )//Wa,没加这个。。。
{
return x < y ? x : y;
} void manacher(int* s)
{
int i,id=0,mx=0;
P[0]=0;
for(i=1;i<=2*n+1;i++)
{
if(mx > i)
P[i] = min(P[2*id-i],mx-i);
else
P[i] = 1;
while(s[i+P[i]]==s[i-P[i]] )
{
P[i]++;
}
if(mx < P[i] + i)
{
mx = P[i] + i;
id = i;
}
}
} void init(int n)
{
int i, j = 2;
s2[0] =-1, s2[1] = -2; for(i=0;i<n;i++)
{
s2[j++] = s1[i];
s2[j++] = -2;
}
s2[j]=-3;
} int main()
{
// printf("%d\n",mm);
int T,ca=1;
scanf("%d",&T);
while(ca<=T)
{
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&s1[i]);
init(n);
manacher(s2);
int ans=0;
for(int i=1;i<=2*n+1;i+=2)
{
// printf("i=%d\tP=%d\n",i,P[i]); for(int j=P[i]+i-1;j-i>ans;j-=2)
{
if(j-i+1<=P[j])
{
ans=max(ans,j-i);
break;//坑
}
} }
printf("Case #%d: %d\n",ca++,ans/2*3);
}
return 0;
}
/*
2
10
2 3 4 4 3 2 2 3 4 4
7
1 2 3 2 1 2 3
*/
Hotaru's problem(hdu5371+Manacher)多校7的更多相关文章
- HDU 5371 Hotaru's problem(Manacher算法+贪心)
manacher算法详见 http://blog.csdn.net/u014664226/article/details/47428293 题意:给一个序列,让求其最大子序列,这个子序列由三段组成, ...
- hdu 5371 Hotaru's problem【manacher】
题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=5371 题意: 给出一个长度为n的串,要求找出一条最长连续子串.这个子串要满足:1:能够平均分成三段 ...
- HDU 5371(2015多校7)-Hotaru's problem(Manacher算法求回文串)
题目地址:HDU 5371 题意:给你一个具有n个元素的整数序列,问你是否存在这样一个子序列.该子序列分为三部分,第一部分与第三部分同样,第一部分与第二部分对称.假设存在求最长的符合这样的条件的序列. ...
- HDU 5371 (2015多校联合训练赛第七场1003)Hotaru's problem(manacher+二分/枚举)
pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序 ...
- hdu5371 Hotaru's problem
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission ...
- 【HDOJ 5371】 Hotaru's problem
[HDOJ 5371] Hotaru's problem Manacher算法+穷举/set Manacher算法一好文:http://blog.csdn.net/yzl_rex/article/de ...
- 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,回文串)
题意:给一个序列,找出1个连续子序列,将其平分成前,中,后等长的3段子序列,要求[前]和[中]是回文,[中]和[后]是回文.求3段最长为多少?由于平分的关系,所以答案应该是3的倍数. 思路:先Mana ...
- hdu5371Hotaru's problem manacher算法
//给一个序列.让求其最大子序列 //这个序列由三段组成.第一段和第二段对称,第一段和第三段一样 //manacher算法求得p[i] //枚举第二段的起点和长度,得到结果 #include<c ...
随机推荐
- 可变参数模拟printf()函数实现一个my_print()函数以及调用可变参数需注意的陷阱
入栈规则 可变参数函数的实现与函数调用的栈帧结构是密切相关的.所以在我们实现可变参数之前,先得搞清楚 栈是怎样传参的. 正常情况下,C的函数参数入栈遵照__stdcall规则, 它是从右到左的,即函数 ...
- LoadRunner的简单使用《第一篇》
LoadRunner是一个用压力测试的软件.这东西比较难上手,光安装就非常麻烦.好不容易一步步跟着安装说明安装好之后,还是用不了. 记录一个问题如下: 导入脚本的时候报错fail to create ...
- 具体解释Ajax技术
Ajax 可以做什么? 现在 Google Suggest 和 Google Maps 使用了 Ajax,通过 Ajax,我们能够使得client得到丰富的应用体验及交换操作,而用户不会感觉到有网页提 ...
- merge into优化sql(转)
使用Merge INTO优化SQL,性能提升巨大 分类: Oracle 2017-04-13 10:55:07 说说背景:开发有个需求,需要对新加的一个字段根据特定的业务逻辑更新数据.TPS_TR ...
- andriod arcgis createPolygons创建带空的面
private void createPolygons() { // create input polygon 1 PointCollection pointsPoly = new PointColl ...
- 我所遭遇过的游戏中间件---HumanIK
我所遭遇过的游戏中间件---HumanIK Autodesk HumanIK游戏中间件,为游戏创建更加可信.真实的角色动画.该中间件的全身逆向运动(FBIK)系统支持角色真实地与所在环境及其它角色进行 ...
- Informatica 常用组件Lookup缓存之五 使用动态查找高速缓存
对于关系查找,当目标表也是查找表时,可能要配置转换以使用动态高速缓存.PowerCenter 将在处理第一个查找请求时创建高速缓存.它将根据查找条件为传递给转换的每行查询高速缓存.当您使用动态高速缓存 ...
- Maximum Subarray leetcode java
题目: Find the contiguous subarray within an array (containing at least one number) which has the larg ...
- mybatis异常 :元素内容必须由格式正确的字符数据或标记组成。
今天同事写一个查询接口的时候,出错:元素内容必须由格式正确的字符数据或标记组成. 错误原因:mybatis查询的时候,需要用到运算符 小于号:< 和 大于号: >,在mybatis配置文 ...
- MyBatis两张表字段名相同产生的问题
MyBatis两张表字段名相同, 会导致bean属性都映射为第一个表的列, 解决方法: 通过设置别名的方式让其产生区别,如 <select id="queryBySekillId&qu ...