Hdu 4513 吉哥系列故事——完美队形II (manacher变形)
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4513
题目描述:
打完题目描述了,点开题目,发现题目是中文,orz.jpg。果断又删掉了,习惯真可怕.......
解题思路:
刚开始,我先manacher求出以 i 为中心的回文串半径存入vis,然后暴力循环每一个位置是不是最长的完美队列。果断T了,胡乱改了几处依旧T。突然灵机一动,发现可以在跑vis数组的时候加一些判定条件,然后直接求出max(vis[i])即可。
学习算法是次要,理解算法思想,锻炼思维灵敏逻辑缜密才最重要。
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std; typedef long long LL;
const int maxn = ;
int vis[maxn*], a[maxn], b[maxn*]; bool judge (int x, int y)
{
for (int i=x+; i<=y/; i++)
if (a[i]<a[i-])
return false;
return true;
} void manacher (int s[], int len)
{
int l = ;
b[l ++] = -;
b[l ++] = -; for (int i=; i<len; i++)
{
b[l ++] = a[i];
b[l ++] = -;
}
b[l] = ; int mx = , id = , ans = ; for (int i=; i<l; i++)
{
vis[i] = mx > i ? min (vis[*id-i], mx-i):; while (b[i-vis[i]] == b[i+vis[i]] && (b[i-vis[i]]==- || b[i-vis[i]]<=b[i-vis[i]+])) vis[i] ++; if (i + vis[i] > mx)
{
mx = i + vis[i];
id = i;
}
ans = max (ans, vis[i]);
} printf ("%d\n", ans - );
} int main ()
{
int T, n;
scanf ("%d", &T); while (T --)
{
scanf ("%d", &n);
for (int i=; i<n; i++)
scanf ("%d", &a[i]); manacher(a, n);
}
return ;
}
Hdu 4513 吉哥系列故事——完美队形II (manacher变形)的更多相关文章
- HDU 4513 吉哥系列故事――完美队形II(Manacher)
题目链接:cid=70325#problem/V">[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher V - 吉哥系列故事――完美队形I ...
- HDU 4513 吉哥系列故事——完美队形II manacher
吉哥系列故事——完美队形II Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希 ...
- HDU 4513 吉哥系列故事――完美队形II
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)
Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成 ...
- HDU 4513 吉哥系列故事——完美队形II (Manacher变形)
题意:假设有n个人按顺序的身高分别是h[1], h[2] ... h[n],从中挑出一些人形成一个新的队形,新的队形若满足以下要求,则就是新的完美队形: 1.连续的 2.形成回文串 3.从左到中间那 ...
- HDU 4513 吉哥系列故事——完美队形II( Manacher变形 )
链接:传送门 思路:根据完美队形的定义,可以得知,完美队形实质上是 回文串 + 序列出现峰,因为是在回文串中再次增加了一个要求,所以可以对 Manacher 进行改造,改造的部分应该为暴力匹配的循环 ...
- HDU 4513 吉哥系列故事——完美队形II
变形的Manacher算法,在扩展的时候要加入限制条件,满足题目中说的从左到中间身高不减. 其他地方倒是没有什么改动.. //#define LOCAL #include <iostream&g ...
- HDU - 4513 吉哥系列故事――完美队形II(manacher)
1.找出一个最长的回文子串,要求中间的值最大,然后向两侧递减. 2.判断条件改为:Ma[i+Mp[i]]==Ma[i-Mp[i]]&&Ma[i-Mp[i]]<=Ma[i-Mp[i ...
随机推荐
- iOS开发之---判断是否是手机号
iOS开发之---判断是否是手机号
- [Pyhton]weakref 弱引用
文档中的解释: https://docs.python.org/2/library/weakref.html wiki 中的解释: 在计算机程序设计中,弱引用.与强引用相对.是指不能确保其引用的对象不 ...
- ArrayList遍历的4种方法
public class ArrayListDemo { public static void main(String args[]){ List<String> list = new A ...
- Hibernate中的merge使用详情解说
merge的作用是:新new一个对象,如果该对象设置了ID,则这个对象就当作游离态处理: 当ID在数据库中不能找到时,用up ...
- hihocoder #1039 : 字符消除 ( 字符串处理类 ) 好久之前做的题目,具体的算法代码中阅读吧
#1039 : 字符消除 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi最近在玩一个字符消除游戏.给定一个只包含大写字母"ABC"的字符串s,消 ...
- HDU1560 DNA sequence —— IDA*算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1560 DNA sequence Time Limit: 15000/5000 MS (Java/Oth ...
- Java经典算法大全
1.河内之塔.. 2.Algorithm Gossip: 费式数列. 3. 巴斯卡三角形 4.Algorithm Gossip: 三色棋 5.Algorithm Gossip: 老鼠走迷官(一) 6. ...
- 转:Apache-Tomcat各发布包说明
下载地址:http://tomcat.apache.org/发布包说明: apache-tomcat-[version].zip---------------------------基本发布包.这些发 ...
- Luogu网校听课笔记(自用
TG助学课——noilinux 8.2 深夜 Noi Linux的使用——darkflames的博客 #include<bits/stdc++.h> using namespace std ...
- Codefroces #404 Div2
A题 分析:把多面体和面数一一对应即可 #include<iostream> #include<map> #include<cstring> #include< ...