吉哥系列故事——完美队形II---hdu4513(最长回文子串manacher)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4513
题意比最长回文串就多了一个前面的人要比后面的人低这个条件,所以在p[i]++的时候判断一下s[i-p[i]]<=s[i-p[i]+2]就可以了;
用最长回文串算法manacher:套一下模板就可以了;
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N = 2e5+; int p[N];
int s[N];
int Manacher(int s[], int n)
{
int Id=, mx = , ans = ;
for(int i=; i<n; i++)
{
if(mx > i)
p[i] = min(p[Id*-i], mx-i);
else
p[i] = ;
while(s[i+p[i]] == s[i-p[i]] && s[i-p[i]]<=s[i-p[i]+] )///要满足的条件是前面的要小于后面的人所以要这样写;
p[i]++;
if(mx < p[i]+i)
{
mx = p[i]+i;
Id = i;
}
ans = max(ans, p[i]);
}
return ans - ;
}
int main()
{
int T, n;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i=; i<n; i++)
scanf("%d", &s[i]);
for(int i=n; i>=; i--)
{
s[i+i+] = s[i];
s[i+i+] = ;
}
s[] = ;
int ans = Manacher(s, *n+);
printf("%d\n", ans);
}
return ;
}
吉哥系列故事——完美队形II---hdu4513(最长回文子串manacher)的更多相关文章
- HDU4513 吉哥系列故事——完美队形II Manacher算法
题目链接:https://vjudge.net/problem/HDU-4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Me ...
- hdu----(4513)吉哥系列故事——完美队形II(manacher(最长回文串算法))
吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)To ...
- HDU4513:吉哥系列故事——完美队形II(Manacher)
吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)To ...
- 吉哥系列故事——完美队形II(hdu4513+Manacher)
吉哥系列故事--完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) T ...
- HDU 4513 吉哥系列故事——完美队形II manacher
吉哥系列故事——完美队形II Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希 ...
- (回文串 Manacher)吉哥系列故事——完美队形II -- hdu -- 4513
http://acm.hdu.edu.cn/showproblem.php?pid=4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) ...
- hdu 4513 吉哥系列故事——完美队形II (manachar算法)
吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) P ...
- HDU 4513 吉哥系列故事――完美队形II(Manacher)
题目链接:cid=70325#problem/V">[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher V - 吉哥系列故事――完美队形I ...
- HDU 4513 吉哥系列故事――完美队形II
http://acm.hdu.edu.cn/showproblem.php?pid=4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) ...
随机推荐
- sama5d3 环境检测 gpio--yx测试
说明: yx0--pioA0 yx1--pioA2 yx2--pioA4 yx3--pioA10 yx4--pioA14 yx5--pioA16 yx6--pioA12 yx7--pioA20 ...
- Android基础总结(八)Service
服务两种启动方式(掌握) startService 开始服务,会使进程变成为服务进程 启动服务的activity和服务不再有一毛钱关系 bindService 绑定服务不会使进程变成服务进程 绑定服务 ...
- Mac下修改应用程序的菜单快捷键!
点击左上角苹果按钮,系统偏好设置 > 键盘 > 快捷键 > 应用快捷键 点击右下角添加按钮,选择chrome程序,输入菜单中文名以及快捷键 1.如何用F5刷新 鼠标悬停在左上角的刷新 ...
- pip和 easy_insall的区别
作为Python爱好者,如果不知道easy_install或者pip中的任何一个的话,那么...... easy_insall的作用和perl中的cpan,ruby中的gem类似,都提供了在线一键 ...
- C++ const关键字修饰引用
//const修饰引用的两种用法 #include<iostream> using namespace std; struct Teacher{ ]; int age; }; void S ...
- 解决阿里云部署 office web apps ApplicationFailedException 报错问题
查找这个问题,确实花费了很长时间,所以具体解析一下问题原因吧. 报错如下: 问题详情链接 New-OfficeWebAppsFarm:Office Online服务无法启动.有关详细信息,请参阅Win ...
- iframe超时处理。。。。
function iframeTimeOut(url, timeOut_callback, width, height) { /// <summary> /// iframe超时处理 // ...
- Python零碎(一)
Python中的__name__和__main__含义详解 在写Python代码和看Python代码时,我们常常可以看到这样的代码: def main(): ...... if __name == & ...
- Nginx配置里的fastcgi_index和index
在配置nginx时有时会遇到, 所以记录一下 location ^~ /wechat/ { index index.php; fastcgi_pass 127.0.0.1:9000; fastcgi_ ...
- 用原生Canvas写贪吃蛇及问题解决
为了学习Canvas,写了这个小游戏贪吃蛇供自己和大家学习 Github: https://github.com/zhiyishou/Gsnake Play On: http://zhiyishou. ...