回文串---Hotaru's problem
Description
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.
Input
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 

, descripting a sequence.
Output
We guarantee that the sum of all answers is less than 800000.
Sample Input
10
2 3 4 4 3 2 2 3 4 4
Sample Output
Source
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int N=;
int p[*N];
int s[*N],str[*N];
int n; void kp()
{
int mx=;
int id;
for(int i=;i<n;i++)
{
if(mx>i)
p[i]=min(p[*id-i],p[id]+id-i);
else
p[i]=;
for( ;i+p[i]<n;)
{
if(str[i+p[i]]==str[i-p[i]])
{
if(str[i+p[i]]==) p[i]++;
else
{
p[i]+=;
}
}
else break;
}
if(p[i]+i>mx)
{
mx=p[i]+i;
id=i;
}
}
} void init()
{
str[]=;
str[]=;
for(int i=; i<n; i++)
{
str[i*+]=s[i];
str[i*+]=;
}
n=n*+;
} int main()
{
int T,Case=;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&s[i]);
if(n<)
{
printf("%d",);
}
init();
kp();
///cout<<p[11]<<"++"<<p[15]<<endl;
int sum=0;
for(int i=;i<=n-;i=i+)
{
if(p[i]-<=sum/*) continue;
int t=p[i];
for(int j=t-;j>=;j=j-)
{
if(j<=sum/*) break;
if(i+j>n) continue;///可能这儿超时;
if(p[i+j]->=j)
{
sum=max(sum,j/*);
break;
}
}
}
printf("Case #%d: %d\n",Case++,sum);
}
return ;
}
回文串---Hotaru's problem的更多相关文章
- HDU 5371(2015多校7)-Hotaru's problem(Manacher算法求回文串)
题目地址:HDU 5371 题意:给你一个具有n个元素的整数序列,问你是否存在这样一个子序列.该子序列分为三部分,第一部分与第三部分同样,第一部分与第二部分对称.假设存在求最长的符合这样的条件的序列. ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- POJ 1159 回文串-LCS
题目链接:http://poj.org/problem?id=1159 题意:给定一个长度为N的字符串.问你最少要添加多少个字符才能使它变成回文串. 思路:最少要添加的字符个数=原串长度-原串最长回文 ...
- BZOJ 2342 回文串-Manacher
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2342 思路:先跑一遍Manacher求出p[i]为每个位置为中心的回文半径,因为双倍回文串 ...
- BZOJ 2565 回文串-Manacher
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2565 题意:中文题 思路:定义L[i],R[i].表示以i为左端点/右端点时,最长回文串长 ...
- POJ 3974 回文串-Manacher
题目链接:http://poj.org/problem?id=3974 题意:求出给定字符串的最长回文串长度. 思路:裸的Manacher模板题. #include<iostream> # ...
- 【BZOJ】3676: [Apio2014]回文串
http://www.lydsy.com/JudgeOnline/problem.php?id=3676 题意:给一个串求回文串×出现次数的最大值.(|S|<=300000) #include ...
- 回文串---Best Reward
HDU 3613 Description After an uphill battle, General Li won a great victory. Now the head of state ...
- 回文串--- Girls' research
HDU 3294 Problem Description One day, sailormoon girls are so delighted that they intend to resear ...
随机推荐
- wpf xaml inlines
string testBold = "<Bold>Sync Now</Bold>"; var ele = System.Windows. ...
- awstats 日志分析工具linux下的安装和使用
合并日志文件可以使用 bash 的sort命令: -o log_all access*.log 也可以使用 awstats 提供的 logresolvemerge.pl -showsteps acc ...
- Clappr——开源的Web视频播放器
巴西著名的门户网站Globo.com(视频播放器),使用的是基于OSMF的Flash组件.在最近几年的发展过程中,Globo为视频平台陆续添加了不少额外功能,例如: 字幕,广告,画中画播放等.然而,由 ...
- 图文安装Windows Template Library - WTL Version 9.0
从http://wtl.sourceforge.net/下载 WTL 9.0,或者点此链接下载:WTL90_4140_Final.zip,然后解压到你的VC目录下面, 我的地址是:C:\Program ...
- messages.exe病毒的清理
一.问题提出 20161021,10点05分,发现messages.exe突然出现在进程中,计算机突然重启,msconfig启动目录里多了一项c:\windows\system32\Drivers\m ...
- 二十一、【.Net开源框架】EFW框架Web前端开发之目录结构和使用FireBug调试方法
回<[开源]EFW框架系列文章索引> EFW框架源代码下载V1.2:http://pan.baidu.com/s/1hcnuA EFW框架实例源代码下载:http://pan.baidu. ...
- LED子系统剖析
写之前,先看一张图: 上次说了LED驱动程序,Linux自身也携带了LED驱动,且是脱离平台的,即LED子系统.操作起来十分简单.但是它的实质却不是那么容易,研究了一个晚上,终于明白了其中一个文件的功 ...
- js转html实体
方法一: 用的浏览器内部转换器实现转换,方法是动态创建一个容器标签元素,如DIV,将要转换的字符串设置为这个元素的innerText,然后返回这个元素的innerHTML,即得到经过HTML编码转换的 ...
- git分享(一)git clone
git clone 命令参数: usage: git clone [options] [--] <repo> [<dir>] -v, --verbose be more ver ...
- Direct2D开发:从资源加载位图
转载请注明出处:http://www.cnblogs.com/Ray1024 一.概述 Direct2D使用Windows图像处理组件 (WIC) 来加载位图.从文件加载位图的方法很简单,而且网上的教 ...