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: ...
随机推荐
- Apach配置本地域名
分三步: 一,开启虚拟域名设置,在路径中找到(apache\apache2.4.9\conf)httpd.conf 配置文件, 去掉 " Include conf/extra/httpd-v ...
- warning:deprecated conversion from string constant to 'char *'
warning:deprecated conversion from string constant to 'char *' 解决方式 #include <iostream> using ...
- EM无法登录,提示ORA-28001: the password has expired (DBD ERROR: OCISessionBegin)
--查看数据库目前的口令期限 sys@TESTDB11>select * from dba_profiles where profile = 'DEFAULT' and resource_nam ...
- USACO 2.2 Preface Numbering
Preface Numbering A certain book's prefaces are numbered in upper case Roman numerals. Traditional R ...
- 常见问题处理之Emoji
所谓Emoji就是一种在Unicode位于\u1F601-\u1F64F区段的字符.这个显然超过了目前常用的UTF-8字符集的编码范围\u0000-\uFFFF.Emoji表情随着IOS的普及和微信的 ...
- Spring《一》
1.支持的注入方式 构建注入,set注入 2.bean属性 id.name.class.singleton(true.false).depends-on="date"(初始化依赖) ...
- Core篇——初探Core的认证,授权机制
目录 1.Cookie-based认证的实现 2.Jwt Token 的认证与授权 3.Identity Authentication + EF 的认证 Cookie-based认证的实现 cooki ...
- 微信公众号测试账号-redirect_uri域名与后台配置不一致,错误代码:10003
微信公众号测试账号-redirect_uri域名与后台配置不一致,错误代码:10003 进入公众平台测试账号. 登录公众账号--"开发者中心"--"公众平台测试账号&qu ...
- GreenDao 3.X之基本使用
在GreenDao 3.X之注解已经了解到GreenDao 3.0的改动及注解.对于数据库的操作,无异于增删改查等四个操作.下面我们将了解GreenDao 3.X如何使用? AbstractDao 所 ...
- Codeforces 994B. Knights of a Polygonal Table
解题思路 将骑士按力量从小到大排序,到第i个骑士的时候,前面的i-1个骑士他都可以击败,找出金币最多的k个. 用multiset存金币最多的k个骑士的金币数,如果多余k个,则删除金币数最小的,直到只有 ...